0

我正在寻找一种在将路径注册到 WatchService 时传递参数的方法。目标是在处理与路径相关的事件时获取这些参数。

WatchService watchService = FileSystems.getDefault().newWatchService();
....
path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE); //I would like to pass some parameters here...
....
key = watchService.take(); // ... so that I can get these parameters here from the WatchKey

知道是否可能吗?

谢谢,米凯尔

4

1 回答 1

1

刚刚发现WatchKey注册时返回的和take()/poll()方法返回的一样。

我设法通过维护外部Map<WatchKey, ....>.

于 2015-06-17T11:52:38.643 回答