How to remove duplicate line in a file
- by Abs
Hi I'm using the below method to write to a file from the Jtextarea and I call this method every 30 second within a Timer but instead to add only new line in file it rewrite the entire lines contained in Jtextarea so then I have duplicate lines. I want to avoid this and update the file just with new lines. Could you help me please.
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();
}
}
}
}