简体   繁体   中英

writing multiple lines to a java file

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM