Reputation: 1645
I'm at my wits end here.
I'm trying to print a few thousands of lines in a file, using the following:
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName, true));
PrintWriter pw = new PrintWriter(bw, true);
The file already consists of text so I'm appending, hence the true argument, in FileWriter.
Now what seems to be puzzling me for the last two hours, is that around 85-90% of the lines get written into the file, while the FIRST 10-15% are not.
There's nothing wrong with the code in terms of logic, because if i print it in the console, all lines are printed.
Am I missing something here?
I only do pw.close() after all output is printed.
Upvotes: 1
Views: 2368
Reputation: 2413
You might want to invoke a manual .flush() command after each time you write to your file in your code just to be very sure that you are writing out correctly.
This is pretty puzzling, do write back if the problem persists.
Hope it helps!
Cheers, Vern
Upvotes: 2