• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

File Reader/Writer problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try flushing the Writer before closing it.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic