我向我的 watchService 注册了一个文件夹:
path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
稍后,我想取消此注册。我知道我需要以某种方式告诉 watchService 我想取消哪个 WatchKey。实现此目的的正确函数是什么?
最佳答案
Watchable
接口(interface) javadoc 中的信息提供了注册 Watchable
对象(例如 Path
实例)的方法 < br/>
公共(public)界面可观看
This interface defines the register method to register the object with a WatchService returning a WatchKey to represent the registration. An object may be registered with more than one watch service. Registration with a watch service is cancelled by invoking the key's cancel method.
所以你只需要做:
WatchKey watchKey = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
...
watchKey.cancel();
关于java - 如何从 Java watchservice 注销目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43950919/