Java 使用WatchService监视远程共享文件夹(Windows/SMB)

Java 使用WatchService监视远程共享文件夹(Windows/SMB),java,remote-access,smb,watchservice,file-watcher,Java,Remote Access,Smb,Watchservice,File Watcher,我正在尝试使用WatchService(java.nio.file.*)监视远程文件夹。对于本地文件夹,一切正常。但是,我无法弄清楚如何监视远程共享。我可以传证件吗 (如果执行代码的用户具有装载共享的权限,那么它也可以工作。) 以下是我的部分代码: public void lunch() throws IOException { boolean recursive = true; Path dir = Paths.get("C:\\test");

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

(如果执行代码的用户具有装载共享的权限,那么它也可以工作。)

以下是我的部分代码:

  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);
        }
}
public void午餐()引发IOException{
布尔递归=真;
Path dir=Path.get(“C:\\test”);
新建监视(dir,recursive).processEvents();
}
公共监视(路径目录,布尔递归)引发IOException{
this.watcher=FileSystems.getDefault().newWatchService();
this.keys=new HashMap();
this.recursive=递归;
if(递归){
系统输出格式(“扫描%s…\n”,目录);
注册主任;
System.out.println(“完成”);
}否则{
注册主任;
}
}
干杯, 斯蒂芬妮来自

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


你有关于如何在远程系统中实现监控的例子吗?我有一个不太复杂的问题。我在linux机器上运行一个watcher服务,监视同一服务器上的文件夹。但是,当我(通过WinSCP/SSH)手动推送这些文件夹中的文档时,观察者只会拾取文件。实际情况是,文件来自扫描仪和传真机,并位于这些文件夹中。在这种情况下,watcher服务不会拾取文件。你知道会有什么问题吗?我已经检查了传入文件的权限。它仅适用于根用户,即运行我的watcher服务的同一用户-