This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Findbugs complains of streams might not get closed. LineNumberReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Findbugs complains of streams might not get closed. LineNumberReader" Watch "Findbugs complains of streams might not get closed. LineNumberReader" New topic
Author

Findbugs complains of streams might not get closed. LineNumberReader

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Hi Guys,

whats wrong with this code ?



Time is what we want the most, but what we use the worst. -- William Penn
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

FileReader.close may throw an IOException. If this occurs then lnReader is never closed. Note that you don't need to explicitly close both of the readers. Closing the LineNumberReader closes its backing Reader as well. Try this:
The LineNumberReader constructor throws no exceptions, so if the FileReader is created then the LineNumberReader is created as well. Except when this call is interrupted by another thread calling System.exit, or an Error (e.g. OutOfMemoryError) being thrown.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Thanks a lot and its fixed !
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Findbugs complains of streams might not get closed. LineNumberReader
 
Similar Threads
reading csv file
Removing prolog from an XML file
How do I read and write a binary file?
how to read a file data into byte array
Cannot Find "Properties" File