I'm trying to monitor the file content and adding any new line to JTextArea. I created thread, which monitor the file, but when the Scanner object reachs the end of file it stop working. I tried very simple method, which create new Scanner object and read the file from the begin, but it isn't good solution. It's the version which stop and do nothing :
public class TextAreaThread implements Runnable {
JTextArea text = null;
File file = null;
Scanner read = null;
public TextAreaThread(JTextArea text, File file) {
this.text = text;
this.file = file;
try{
read = new Scanner(file);
}catch(FileNotFoundException e){
JOptionPane.showMessageDialog(null,"Wrong file or file doesn't exist","Error",JOptionPane.ERROR_MESSAGE);
}
}
public void run() {
while(true){
while(read.hasNext())
text.append(read.nextLine()+"\n");
try {
wait(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}