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

5

25

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.

Desdemona answered 8/7, 2009 at 6:31 Comment(2)
This question appears to be off-topic because this is a programming site. See What topics can I ask about here in the Help Center. Perhaps Software Recommendations Stack Exchange would be a better place to ask.Catt
Java 7 introduced WatchService.Pericranium
K
25

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.

Kolkhoz answered 8/7, 2009 at 8:44 Comment(0)
M
7

If you are comfortable working on the bleeding edge of Java, have a look at JSR 203: More New I/O APIs aka nio2 which is due out in Java 7.

A new filesystem interface that supports bulk access to file attributes, change notification, escape to filesystem-specific APIs, and a service-provider interface for pluggable filesystem implementations;

Mcnew answered 8/7, 2009 at 8:50 Comment(0)
E
6

jpathwatch is another option. It implements Java 7′s API for directory monitoring, so it is easy to port to Java 7 if desired.

Edwardoedwards answered 1/7, 2010 at 6:13 Comment(0)
R
4

Why does it have to be Java?

The Library that is going to use platform specific API must have native code, so essentially the library is going to be wrappers around the native code that makes the usage of the different APIs transparent.

I suggest if you do not find the Library your self then you will have to either use brute force as you call it, or call the native API using JNI for each platform.

Rayerayfield answered 8/7, 2009 at 6:40 Comment(1)
Yes, that is essentially what such a library would be, a wrapper. But I was hoping that something like that already exists. (It exists, but not free/open source)Desdemona
B
0

Two more options that currently use polling:

However, because both projects have large active communities, they will likely be updated in the future to support the Java 7 WatchService (FileSystem.newWatchService()), which does use the underlying platform's notification facilities, if any.

Both libraries also provide a useful abstraction layer for integrating with various other transports and systems, so that your main application code is not dependent on the inputs being received from a filesystem.

Brucie answered 23/8, 2012 at 15:29 Comment(1)
A comment explaining the downvote would be helpful...Brucie

© 2022 - 2024 — McMap. All rights reserved.