tags:

views:

129

answers:

2

I'd like to be notified when a file has been created, deleted or changed, but not using polling mechanism.

I have surveyed related Java API that can use.(EX:JNotify, JPathWatch and JXFileWatcher)

Those APIs provide file monitor by using native component on OS. But I met the same problem is that they can't run on Linux 64bits, because native component in those APIs donen't support Linux 64bits, and this confused me for a long time.

I also know that there'll be a WatchService API as part of NIO2 in JDK7, but JDK7 has not released yet.

So, can any one suggest me a better solution? Very Thanks.

+2  A: 

have you tried inotify-java ?

Also, as far as I can see, native component of JNotify comes in C-sources, so you can compile it yourself for any platform.

zed_0xff
Very thanks!! I will try it, but I am not familiar with C complier.I need to study it, hoping not too complicated.
Tim
@Tim, it looks like inotify has "x86_64" binaries, so you won't even need to compile.
Michael Aaron Safyan
Great! I think inotify-java can run on Linux 64bits. try it latter!
Tim
It works!'INotify-Java' can run on Linux 64bits, because it provided native components for Linux 32bits and 64bits.This is a good way to do file monitor on Linux 64bits by adopting inotify-java API directly without any other efforts, but not for other platforms such as Windows or MAC OS.If you are not running on Linux 64bits, other APIs I mentioned before(JNotify, JPathWatch and JXFileWatcher) are very useful too and can run on different platforms.
Tim
A: 

It works! 'INotify-Java' can run on Linux 64bits, because it provided native components for Linux 32bits and 64bits. This is a good way to do file monitor on Linux 64bits by adopting inotify-java API directly without any other efforts, but not for other platforms such as Windows or MAC OS. If you are not running on Linux 64bits, other APIs I mentioned before(JNotify, JPathWatch and JXFileWatcher) are very useful too and can run on different platforms.

Tim