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

孤街浪徒 提交于 2019-11-26 18:39:33
Brian Agnew

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.

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;

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!