Hi guys I am writing a small application in java where it reads a text file and parses the contents. My problem is my program will keep on reading the file because its inside a loop. My solution was to implement similar to what I usually do in linux like (see below)
ls -l -ctime
or
ls -l -atime
where it detects when the files was last accessed or written If you solution can be done in java or some windows command can you please let me know. Thanks
Update:
Thanks very much for helping
Westons Solution
public static long checkLastFileModification() throws InterruptedException{
File file = new File(fileName);
long lastProcessed = -1;
while (true){
long lastModified = file.lastModified();
if (lastProcessed != lastModified){
lastProcessed = lastModified;
System.out.println("Last accessed : " + lastModified);
//read the file in reverse order
}
else{
System.out.println("No file access.... sleeping for 5 secs ");
Thread.sleep(5000);
}
}
}