Two Laptop Bag*
The moose likes I/O and Streams and the fly likes File Reader/Writer problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "File Reader/Writer problem" Watch "File Reader/Writer problem" New topic
Author

File Reader/Writer problem

Vsam hr
Greenhorn

Joined: Dec 25, 2009
Posts: 5
I have written a I/O code wherein the I/O is done using


The File which I am reading from contains large no. of records.Each records contains a few columns. On reading the records and am modifying them and writing them to the Output file. I am using while loop for reading each record.

The problem arises for the last record. When writing the last record into the output file, only few columns get written. The entire last record isnt written. This causes problems when i want to read this output file as the last record is not complete.
I am also closing the BufferedWriter using bw.close();

Please help in explaining why only the last record isnt being completely written.
Thanks in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42050
    
  64
Try flushing the Writer before closing it.


Ping & DNS - my free Android networking tools app
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Ulf Dittmer wrote:Try flushing the Writer before closing it.


To quote the Javadoc for BufferedWriter.close()

Closes the stream, flushing it first.


The implication is that if your solution works then there is a bug in BufferedWriter.

My bet is that the OP has a bug in his code but we don't have access to it.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
 
GeeCON Prague 2014
 
subject: File Reader/Writer problem