在java中如何检测文件系统已经改变 [英] How to detect filesystem has changed in java
本文介绍了在java中如何检测文件系统已经改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为我想我可以打电话给 java.io.file.lastModified 每隔几秒钟,但我不喜欢这个解决方案的声音。
alfred @ alfred-laptop:〜/ testje $ java -version
java版本1.6.0_18
Java™SE运行时环境(build 1.6.0_18-b07)
Java HotSpot™服务器虚拟机(构建16.0-b13,混合模式)
解决方案
请看 JNotify ,它执行这种类型的监视。
Java 7将具有一些更高级的API( $ b $
I would like to know how to efficiently implement filesystem changes in java? Say I got a file in a folder and modify that file. I would like to be notified by java about this change as soon as possible(no frequently polling if possible.).
Because I think I could call java.io.file.lastModified every few seconds but I don't like the sound of that solution at all.
alfred@alfred-laptop:~/testje$ java -version
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Server VM (build 16.0-b13, mixed mode)
解决方案
Take a look at JNotify, which performs this type of monitoring.
Java 7 will have some more advanced APIs (WatchService) for this sort of work which will eliminate polling on the OSes that support this.
这篇关于在java中如何检测文件系统已经改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文