我正在寻找一种在注册到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知道有可能吗?
谢谢你,Mickael
发布于 2015-06-17 11:52:38
我刚刚发现,注册时返回的WatchKey与take()/poll()方法返回的相同。
我通过维护一个外部Map<WatchKey, ....>来解决这个问题。
https://stackoverflow.com/questions/30889722
复制相似问题