Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with FileWriter and BufferedWriter

807603Nov 17 2006 — edited Nov 26 2007
Hi,

I have a scenario where i need to process millions of records to a file.
I am giving the sample code that i am using.

File destfile = new File(pathName, destFileName);
FileWriter fileWriter = new FileWriter(destfile);
BufferedWriter fileOutput = new BufferedWriter(fileWriter);

for(int x=0;x<size;x++)
{
fileOutput.write("my content"+x);
}
fileOutput.close();
fileWriter.close();

The Problem is only some part of the content is being written to the file.
so i used fileOutput.flush(); and fileWriter.flush(); after each write()
statement. This solved my problem at that time. Now again the
problem re-occured in some other machine when i executed the
same program.

what could be the problem?

Also i have seen the API for FileWriter().
when we have a function write(String s) in the fileWriter, what difference does it make using BufferedWriter.write(), instead of FileWriter.write() directly.

Please advice.

- Raju
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 24 2007
Added on Nov 17 2006
7 comments
1,233 views