0

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

1

1 Answer 1

4
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.

Documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.