阅读背景:

Java - 使用WatchEvent抑制未经检查的强制转换警告是否安全?

来源:互联网 

I have the following test code:

我有以下测试代码:

FileSystem fs = FileSystems.getDefault();
Path conf = fs.getPath(".");
WatchKey key = null;
try {
    WatchService watcher = fs.newWatchService();
    conf.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
    while(true) {
        key = watcher.take(); // waits
        for (WatchEvent<?> event : key.pollEvents()) {

            WatchEvent.Kind<?> kind = event.kind();
            if (StandardWatchEventKinds.OVERFLOW == kind) continue;

            WatchEvent<Path> ev = (WatchEvent<Path>)event;
            Path file = ev.context();
            System.out.println(file);
        }
    }
} catch (IOException | InterruptedException e) {
    throw new RuntimeException(e.getMessage(), e);
}
F



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: