Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a sophisticated file system monitor for Java which is freeware or open source? [closed]

Tags:

I'm looking for a Java library which can notify me about changes on the file system.

I found some free libraries, but they all use brute-force detection, i.e. polling in regular intervals. And the other ones are always commercial.

What I'm looking for is a library which uses the file monitor functions from the OS, i.e. FindFirstChangeNotification for Win32, FAM for Linux and whatever is available on other OS. I don't mind if brute-force is used as fallback, but for Windows and Linux it should use the available OS features.

like image 530
Daniel Rikowski Avatar asked Jul 08 '09 06:07

Daniel Rikowski


People also ask

What is WatchService in Java?

A watch service that watches registered objects for changes and events. For example a file manager may use a watch service to monitor a directory for changes so that it can update its display of the list of files when files are created or deleted.

Can we monitor a directory for adding new files in Java?

Create a WatchService "watcher" for the file system. For each directory that you want monitored, register it with the watcher. When registering a directory, you specify the type of events for which you want notification. You receive a WatchKey instance for each directory that you register.


1 Answers

JNotify seems to do what you require.

Polling a filesystem (say, a directory for update time changes) won't impose a significant load on your system, and shouldn't be discounted. Apps like Tomcat etc. use this for managing hot deploys with few problems.

It's not a lot of help now, but the upcoming Java 7 has a WatchService precisely for this.

like image 152
Brian Agnew Avatar answered Sep 20 '22 12:09

Brian Agnew