How to remove duplicate line in a file
Posted
by
Abs
on Stack Overflow
See other posts from Stack Overflow
or by Abs
Published on 2012-03-20T19:18:46Z
Indexed on
2012/03/21
23:30 UTC
Read the original article
Hit count: 264
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();
}
}
}
}
© Stack Overflow or respective owner