使用WatchService监视远程共享文件夹(Windows/SMB) [英] Monitor remote shared-Folder (Windows/SMB) using WatchService

查看:742
本文介绍了使用WatchService监视远程共享文件夹(Windows/SMB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用WatchService(java.nio.file.*)监视远程文件夹.本地文件夹一切正常.但是,我无法弄清楚如何监视远程共享.我可以通过凭证吗?

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);
        }
}

干杯, 斯蒂芬妮

推荐答案

来自

如果监视的文件不在本地存储设备上,则可以检测到文件的更改是特定于实现的.特别是,不需要检测对在远程系统上执行的文件的更改.

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.

这篇关于使用WatchService监视远程共享文件夹(Windows/SMB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆