Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Reader/Writer problem

 
Vsam hr
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try flushing the Writer before closing it.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic