本文介绍了JAVA NIO Watcher:如何检测持久(复制)操作的结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在dir中对新引入的文件进行一些ZIP动作。我在那里获得了CREATE事件,它被触发了。复制到该目录的操作需要一些时间。

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.

所以我在访问文件时得到ACCESS_DENIED,被另一个进程锁定。

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

NIO是否提供类似LOCK Released的内容,或者我是否需要以某种方式轮询文件以释放锁?如下所述:http://stackoverflow.com/questions/750471/how-to-know-whether-a-file-copying-is-in-progress-complete-in-java-1-6

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

感谢您的帮助。

Gerd

推荐答案

将文件复制到不同的目录中;完成后,将其移至监视目录。

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);

观察者将看到一个CREATE事件

the watcher will see one CREATE event

这篇关于JAVA NIO Watcher:如何检测持久(复制)操作的结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:56