使用WatchService监视远程共享文件夹(Windows/SMB) [英] Monitor remote shared-Folder (Windows/SMB) using WatchService
本文介绍了使用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);
}
}
干杯, 斯蒂芬妮
推荐答案
查看全文