public class Tail {
long interval;
String filepath;
public void run() {
long filePointer = 0;
while (true) {
Utils.sleep(interval);
try (RandomAccessFile file = new RandomAccessFile(filepath, "r")) {
long fileLength = file.length();
if (fileLength > filePointer) {
file.seek(filePointer);
String line = null;
while ((line = file.readLine()) != null) {
// todo
}
filePointer = file.getFilePointer();
}
} catch (FileNotFoundException e) {
;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}