java 在Java WatchService上注册目录及其子目录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 在Java WatchService上注册目录及其子目录相关的知识,希望对你有一定的参考价值。

/**
 * Register the given directory, and all its sub-directories, with the WatchService.
 */
private void registerAll(final Path start) throws IOException {
    // register directory and sub-directories
    Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
            throws IOException {
                dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
                return FileVisitResult.CONTINUE;
        }
    });
}

以上是关于java 在Java WatchService上注册目录及其子目录的主要内容,如果未能解决你的问题,请参考以下文章

Java 7 WatchService 对其他人来说很慢吗?

Java 7 NIO watchservice vs jpathwatch

使用 Java WatchService 监视文件夹中的文件夹

Java 文件系统监控(WatchService)

Java WatchService 在观看映射驱动器时不生成事件

Java 项目中一种简单的动态修改配置即时生效的方式 WatchService