For some reason this code results in a truncated text.txt file. It should (according to me) write out 1000 results, but the output file has various amounts of lines (dependi
Two things.
Try something like:
Writer out = null;
try {
out = new BufferedWriter(new FileWriter("test.txt"),16*1024);
// Write some stuff
out.flush();
} finally {
try {
out.close();
} catch (Exception exp) {
}
}
Try and remember, it's a "buffer". That means that it's keeping stuff stored in memory until it decides it needs to be written or your explicitly ask it to "flush" it's contents.
Also, you should always close
your streams. This prevents possible locked file issues and file handle issues :P