Suggestions:
true
would allow appending text into the File if it exists. println(...)
on your PrintWriter, writing your new text into the file.close()
of the PrintWriter should be in the try's finally block.e.g.,
PrintWriter pw = null;
try {
File file = new File("fubars.txt");
FileWriter fw = new FileWriter(file, true);
pw = new PrintWriter(fw);
pw.println("Fubars rule!");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (pw != null) {
pw.close();
}
}
Easy, no?