2

I need to make some ZIP- action on a freshly introduced file in a dir. There I subsribe for the CREATE event, which is fired. The copy operation into that directory takes some time.

So I get ACCESS_DENIED, "locked by another process" when accessing the file.

Does NIO provide something like "LOCK Released" or do I need to poll the file somehow for the lock to be released ? Like described here :http://stackoverflow.com/questions/750471/how-to-know-whether-a-file-copying-is-in-progress-complete-in-java-1-6

Thanks for any help.

Gerd

user1226230
  • 381
  • 1
  • 3
  • 11

2 Answers2

1

copy the file in a different directory; after it's done, move it to the watched directory.

java.nio.file.Files.move(srcFile, targetFile, StandardCopyOption.ATOMIC_MOVE);

the watcher will see one CREATE event

irreputable
  • 44,725
  • 9
  • 65
  • 93
  • Thanks for the comment. I will check it. But as stated in the comment below, the copy operation appears without my influence. Sometimes is FTP, sometimes via SMB/SAMBA. In order to find the end of the copy operation, I tried to supervise the file written with: - File.isModified() - File.length() - File.isWrite() – user1226230 Jan 18 '13 at 08:04
0

Modify the copy operation so that an additional, small file is written to the same directory, after the first, larger file is written. The filename could be the name of the original file, plus an extension.

Your watcher would look for files with this extension, chop it off to get the original filename, and then start the Zip-action.

Another option could be that your copy operation writes a file with an extension other than the one you look for. When done, it renames the file to give it the correct extension.

Werner Kvalem Vesterås
  • 10,226
  • 5
  • 43
  • 50