Reputation: 666
I'm trying to create an error report in Java, but the file reader writes over the same line every time I find a new error, so all that displays is the last error. How would I prevent this?
public void errorReport(String error)
{
try {
FileWriter fw = new FileWriter(file);
PrintWriter pw = new PrintWriter(fw);
pw.write(error);
pw.close();
} catch (IOException e)
{
e.printStackTrace();
}
} // end error report
Upvotes: 0
Views: 982
Reputation: 59343
FileWriter fw = new FileWriter(file, true);
The second argument is "append mode." If it is true
, then the FileWriter
will append lines instead of writing over them.
Upvotes: 4