Problems with FileWriter and BufferedWriter
807603Nov 17 2006 — edited Nov 26 2007Hi,
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