我正在寻找一种在向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
知道有没有可能?
谢谢,
米凯尔
最佳答案
我只是发现注册时返回的WatchKey
与take()/poll()
方法返回的相同。
我设法通过维护一个外部Map<WatchKey, ....>
来解决它。