Java远程监听一个folder,使用WatchService监视远程共享文件夹(Windows / SMB)

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

this.recursive = recursive;

if (recursive) {

System.out.format("Scanning %s ...\n", dir);

registerAll(dir);

System.out.println("Done.");

} else {

register(dir);

}

}

Cheers,

Stephanie

解决方案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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值