Detecting a file read in Java

It's easy to detect a record or file change, but I can't think of a way to detect a read file. Here is the script.

Program X (with which I do not control) READS Sample.text and CHANGE it. It should be noted that program X closes the stream immediately after READ.

I have to write a program to record duration / time from READ in MODIFICATION Sample.txt. For example, program X reads Sample.txt at 5:00 PM and changes it at 7:25 pm, so the total duration is 2 hours and 25 minutes.

Is there a package or workaround to detect when / if Sample.txt was read by program X? Please note that READ is what I want to define as intended for MODIFIED, since java.nio.file can detect file modification.

+4
source share
2 answers

Sounds like reading one of the BasicFileAttributes , this lastAccessTimeis what you are looking for.

+4
source

Hope this helps -

  • Track file reading time in program X.
  • Always save the reading time in the database.
  • After changing the file, find the difference between the recorded read time and the modified time.
0
source

All Articles