java - 在 JAVA watchservice api 中,我如何定位所有驱动器
问题描述
我可以让手表服务在 JAVA 中工作,但我想让它在所有驱动器和文件夹中工作,而不是针对一个驱动器/文件夹。
import java.io.IOException;
import java.nio.file.*;
/**
*
* @author Admin
*/
public class NewClass2 {
public static void main(String[] args) throws IOException {
WatchService watchService = FileSystems.getDefault().newWatchService();
Path directory = Paths.get("C:\\");
WatchKey watchKey = directory.register(watchService,
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
while (true) {
for (WatchEvent<?> event : watchKey.pollEvents()) {
System.out.println(event.kind());
Path file = directory.resolve((Path) event.context());
System.out.println(file + " was last modified at " + file.toFile().lastModified());
}
}
}
}
解决方案
推荐阅读
- php - remove_submenu_page('woocommerce', 'wc-admin'); 功能不删除仪表板
- flutter - 是否可以在 Flutter 中向 Future 发送查询类型的 url?
- sql - 减去日期时使用 CTE 的 Postgres SQL
- python - 使用Python中根节点的小写属性抛出的ElementTree进行XML解析
- javascript - 我们可以在点击时删除 HTML 元素的边框吗?但保持边界为焦点
- python - 在 Python 中比较 String 和 Naive 格式的时间
- c# - C# - 查找特定值是否在列表中具有重复项
- node.js - 如何将图像上传到 KeystoneJS GraphQL 端点?
- r - 为不同的数据集Winsorizing相同的变量
- mysql - 前台不发送任何内容