java 7 /java.nio.file 文件监控!!!

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,还弄不明白它是在那初始化的!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值