Shailesh_B
Shailesh_B

Reputation: 41

File System Change Monitoring through Java

I want to monitor changes with selected directories on my system through java. I have bit idea about watchservice in java 7. But watchservice only returns directory name to which change event (MODIFY, DELETE) occurs. On the other side, I want all information about change like user who made changes, time at which change takes place etc.

It is something like a want to read change journals on NTFS file system. Is there any other way available in Java to record such changes asynchronously ? ...

Thanks in advance.

Upvotes: 4

Views: 4193

Answers (4)

Trey
Trey

Reputation: 11158

You might find Event Programming Example: Google Guava EventBus and Java 7 WatchService useful. I'm trying to do asynchronous file watching as well and am likely going to use some derivative of this.

Or, if you are willing to skip direct management of the WatchService, give the Camel file endopoint a try.

Upvotes: 0

Adriano Repetti
Adriano Repetti

Reputation: 67138

If you just want to get notified when something happens you can use one of the libraries posted in the answers.

If you want to do it by yourself using a small example (and you're limited to Windows) take a look at this article about Java Native Interface. Using the ReadDirectoryChanges function you can decide to receive asynchronous notifications.

If you really need to know WHO made that changes then...good luck! For what I know (and for Windows only) this isn't a simple topic because Windows doesn't save that information. You can get it via JNI with Object Auditing but you have to enable it and it'll slow down a little bit your system. Take a look at this post for some details.

Upvotes: 0

Anish Dasappan
Anish Dasappan

Reputation: 415

if you are using java7 have a look at java.nio.file.FileSystem and WatchService

for more info refer Oracle tutorial

Upvotes: 3

alexwen
alexwen

Reputation: 1128

Not sure if you have the capability to add import libraries to your project but commons-io has a FileAlterationObserver that may suit your needs:

http://commons.apache.org/io/api-release/org/apache/commons/io/monitor/FileAlterationObserver.html

Upvotes: 3

Related Questions