小编jfa*_*ior的帖子

Java 7 WatchService - 进程无法访问该文件,因为它正由另一个进程使用

我按照观察变更目录 Java7 nio2教程,使用代码示例WatchDir.java以递归方式监视目录的全部内容.

代码如下所示:

// Get list of events for the watch key.
for (WatchEvent<?> event : key.pollEvents()) {
// This key is registered only for ENTRY_CREATE events, but an OVERFLOW event 
// can occur regardless if events are lost or discarded.
if (event.kind() == OVERFLOW) {
    continue;
}

// Context for directory entry event is the file name of entry.
@SuppressWarnings("unchecked")
WatchEvent<Path> ev = (WatchEvent<Path>)event;
Path fileName = ev.context();
Path fullPath = dir.resolve(fileName);

try {
    // …
Run Code Online (Sandbox Code Playgroud)

java file-io java-7 watchservice

8
推荐指数
1
解决办法
7159
查看次数

标签 统计

file-io ×1

java ×1

java-7 ×1

watchservice ×1