嗨,我正在使用以下方法从 Jtextarea 写入文件,并且我在 Timer 中每 30 秒调用一次此方法,而是只在文件中添加新行,它会重写 Jtextarea 中包含的整行,所以我有重复的行. 我想避免这种情况并仅使用新行更新文件。请问你能帮帮我吗。
public void loger() {
FileWriter writer = null;
try {
writer = new FileWriter("MBM_Log_"+date()+".txt" , true);
textArea.write(writer);
} catch (IOException exception) {
System.err.println("log error");
exception.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException exception) {
System.err.println("Error closing writer");
exception.printStackTrace();
}
}
}
}