Is it somehow possible to keep track of the current file state when opening/editing a file by calling Desktop.getDesktop().edit(File myFile)?
My goal is to lock a shared file (which is stored in a common database) while one of many users is editing the file and finally when he saves the changes to the file I get some kind of “event” so that I can unlock the file again as soon as he closed the corresponding application resp. file.
Any help highly appreciated! Thanks in advance!
To receive notifications about filesystem changes you use a WatchService (since Java 7).
You register a service and watch for
ENTRY_MODIFYevent type.Nice walk-through is available here: http://docs.oracle.com/javase/7/docs/api/java/nio/file/WatchService.html
If you can’t use Java 7 you should look at jnotify.