The commons FileUtils look pretty cool, and I can't believe that they cannot be made to append to a file.
File file = new File(path);
FileUtils.writeLines(file, printStats(new DateTime(), headerRequired));
The above just replaces the contents of the file each time, and I would just like to keep tagging this stuff to end just as this code does.
fw = new FileWriter(file, true);
try{
for(String line : printStats(new DateTime(), headerRequired)){
fw.write(line + "\n");
}
}
finally{
fw.close();
}
I've searched the javadoc but found nothing! What am I missing?
You can use IOUtils.writeLines(), it receives a Writer object which you can initialize like in your second example.