I want to read from a text file such that whenever i add a line to my text file and save it, the java program should read that particular line and print it. So far i have something like this:
FileReader fileReader = new FileReader(filename);
BufferedReader bufReader = new BufferedReader(fileReader);
while (true){
if (bufReader.ready()){
String line = bufReader.readLine();
System.out.println(line);
continue;
}
else {
Thread.sleep(5000);
continue;
}
}
This code doesn't print the new lines once the program is running and i update the text file and save. Is there a way how i could achieve this?