似乎没有内置的文件扩展名过滤器(就像使用旧的 java.io.FileFilter 接口一样)。我通过在处理代码中添加“if”语句解决了同样的问题,如下所示:
// Watcher gives key and you get event...
WatchEvent<Path> ev = (WatchEvent<Path>) event;
Path file = dir.resolve(ev.context());
if (isCorrectFileType(file)) {
// Do you processing here.
}
Run Code Online (Sandbox Code Playgroud)
以及简单的检查:
private boolean isCorrectFileType(Path file) {
return (file.toString().endsWith(".xml"));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2467 次 |
| 最近记录: |