I would say, that you should at one point flsh your writer and close the filewriter...
Also declare the FileWriter as variable:
FileWriter fw = new FileWriter(f);
PrintWriter pw=new PrintWriter(fw);
try {
pw.flush();
pw.close();
fw.flush();
fw.close();
} catch (IOException e) {
System.err.println("Error writing to file:" + e.getMessage());
}
This should be done with any file, when you finished writing to it. To get unfinished content before ending the write, just use the flush()-Method to get content to Disk...
Hope this helps,
Cheers, Arndt