public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(FileSystems.getDefault());
try {
WatchService watchService = FileSystems.getDefault().newWatchService();
String watchDir="Z:\\test";
File watchDirFile = new File(watchDir);
System.out.println(watchDirFile.isDirectory());
Path watchDirPath = watchDirFile.toPath();
WatchKey watchKey = watchDirPath.register(watchService,StandardWatchEventKinds.ENTRY_CREATE,StandardWatchEventKinds.ENTRY_MODIFY);
try {
while(true){
watchKey=watchService.take();
System.out.println("==========");
for (WatchEvent event : watchKey.pollEvents()) {
System.out.println("An event was found after file creation of kind" + event.kind()+". The event occurred on file" + event.context());
}
watchKey.reset();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这个伤不起啊!!!不用了!
监测本地可用,但是监测碗盘不好用,
本来第一进入监视的话,first应该是空的,本地监控first是null,而监控贡献文件时会first不是null,还弄不明白它是在那初始化的!