Monitor remote shared-Folder (Windows/SMB) using WatchService

不羁岁月 提交于 2020-01-04 03:00:47

问题


I am trying to monitor a remote folder using WatchService (java.nio.file.*). Everything works fine for local folders. However I was unable to figure out how to monitor a remote share. Can I pass credentials along?

(If the user executing the code has the rights to mount the share it works as well.)

Here are parts of my code:

  public void lunch() throws IOException {
        boolean recursive = true;
        Path dir = Paths.get("C:\\test");
        new Watch(dir, recursive).processEvents();
    }

    public Watch(Path dir, boolean recursive) throws IOException {
        this.watcher = FileSystems.getDefault().newWatchService();
        this.keys = new HashMap<WatchKey,Path>();
        this.recursive = recursive;

        if (recursive) {
            System.out.format("Scanning %s ...\n", dir);
            registerAll(dir);
            System.out.println("Done.");
        } else {
            register(dir);
        }
}

Cheers, Stephanie


回答1:


From WatchService javadoc

If a watched file is not located on a local storage device then it is implementation specific if changes to the file can be detected. In particular, it is not required that changes to files carried out on remote systems be detected.



来源:https://stackoverflow.com/questions/26577788/monitor-remote-shared-folder-windows-smb-using-watchservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!