1

For my application I need to keep track of all files that are touched using the OS (Windows or Mac). By touching I'm talking about opening files or saving files. Is this possible at all? And if yes, what keywords should I google?

Jayan
  • 18,003
  • 15
  • 89
  • 143

2 Answers2

4

Java 7 has some features for that - Watching a directory for changes - API

Here is a blog regarding the same Watching a directory for changes

Vino
  • 1,544
  • 1
  • 18
  • 26
  • 2
    +1 but please provide more details than just a link. You should edit your answer and provide an excerpt of the io notification. Maybe some sample code. – Gray Apr 02 '12 at 12:58
  • 1
    As far as I know notifications only help with write access. I doubt that you can be notified of pure read-only access. – Joachim Sauer Apr 02 '12 at 12:59
2

Apache commons io library, if you want to use with Java 6.*

extending more: On a second look here is question in SO { Is there a sophisticated file system monitor for Java which is freeware or open source? } It may be the one Roflcoptr is interested. It talks about http://jnotify.sourceforge.net/. I did not use that for getting info on reading, though.

Community
  • 1
  • 1
Jayan
  • 18,003
  • 15
  • 89
  • 143
  • Thanks a lot, that's really cool, but it seems that it doesn't track just read access. – RoflcoptrException Apr 02 '12 at 13:13
  • @Roflcoptr: pure read access probably can't be traced from pure Java code at all. It *is* possible when writing lower level code (at least on Windows). Why do you need this? – Joachim Sauer Apr 02 '12 at 14:07
  • That would also be possible for me. In the end, I need a Java application that lists a log of all files that were opened. It wouldn't a problem for me to write lower level code to directly access Windows and then provide an interface to my Java app. – RoflcoptrException Apr 02 '12 at 14:08
  • @JoachimSauer I tried for example JNotify, but from there I don't get any notification if a file is opened. Just if it is saved, modified or created. – RoflcoptrException Apr 03 '12 at 08:06