gpt4 book ai didi

java - 使用 WatchService 监控远程共享文件夹 (Windows/SMB)

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:22:52 29 4
gpt4 key购买 nike

我正在尝试使用 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);
}
}

干杯,斯蒂芬妮

最佳答案

来自 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.

关于java - 使用 WatchService 监控远程共享文件夹 (Windows/SMB),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26577788/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com