I had a requirement to write a java code to listen continues changing text file.I have used following code to do that.
public void listenServer() throws IOException {
Reader fileReader = new FileReader("/home/vaani/server.log");
BufferedReader input = new BufferedReader(fileReader);
String line = null;
while (true) {
if ((line = input.readLine()) != null) {
System.out.println(line);
continue;
}
try {
Thread.sleep(1000L);
} catch (InterruptedException x) {
Thread.currentThread().interrupt();
break;
}
}
input.close();
return isException;
}
No comments:
Post a Comment