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