我有一个监视, AND事件WatchService
的目录树。问题是 a 的上下文只给出了一个 Path 对象。在删除事件中,我不确定路径是否引用了常规文件的目录。ENTRY_CREATE
ENTRY_DELETE
ENTRY-MODIFY
WatchEvent<?>
WatchKey key = null;
try {
key = watcher.take();
} catch (InterruptedException e) {
e.printStackTrace();
}
for (WatchEvent<?> event : key.pollEvents()) {
if (event.kind() == StandardWatchEventKinds.OVERFLOW) {
continue;
}
Path parent = (Path) key.watchable();
Path p = parent.resolve((Path) event.context());
for (DirectoryModifiedListener listener : listeners) {
if (event.kind() == StandardWatchEventKinds.ENTRY_DELETE) {
// only do this if p referred to a file, not a directory
listener.onFileCreated(p);
}
}
}
我的问题是如何确定路径是否p
引用了已删除的文件或目录?API公开的内容甚至可能吗?