Detect file system changes on Samba share with Java on Windows
for a 开发者_开发问答recent project I need to detect file system changes on a mapped Samba share from java on windows: Creates, updates and removes. At the moment I am using a folder poll that maintains a list of files and their modified timestamp to look for events.
But my problem is that this folder poll only peeks into the folder at certain times (every 10 seconds for example), so an updated file can be updated twice between two polls without recognizing.
Is there any way to get events from windows inside Java whenever a file event occours on that mappep Samba share?
Thanks!
Java doesn't have anything in the current IO api for dealing with file notifications from the O/S.
Java 7 will have a new IO API JSR-203 that has a watch file API that will either use native O/S notifications or polling if notifications are not supported to detect file changes.
In the meantime you could look to see if someone has implemented a library that allows you to hook into the O/S notifications via JNI. I think that IntelliJ IDEA uses a native lib for this purpose.
Looking on Sourceforge I've found jfilenotify but i've never used it.
Alternatively you could increase your sampling frequency (but this will start to hammer your filesystem) or change how your files are written out by adding a version number to the filename/folder so that you can easily tell when something has changed.
According to this forum entry TeamDev JNIWrapper is capable of doing this like I want it. I just purchased a copy. Thank you and
Greetz, GHad
精彩评论