Java中的文件更改监听器 [英] File changed listener in Java

查看:271
本文介绍了Java中的文件更改监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文件系统中的文件被更改时,我希望得到通知。我只找到了一个线程来调查lastModified File属性,显然这个解决方案不是最优的。

I'd like to be notified when a file has been changed in the file system. I have found nothing but a thread that polls the lastModified File property and clearly this solution is not optimal.

推荐答案

建模此实用程序的唯一方法是在目录上进行线程轮询,并对文件的属性进行监视。但是您可以使用模式为这样的实用程序开发适配器。

At the low level the only way to model this utility is to have a thread polling on a directory and keeping a watch on the attributes of the file. But you can use patterns to develop a adapter for such a utility.

例如,像Tomcat和其他人这样的j2ee应用程序服务器具有自动加载功能,其中一旦部署描述符更改或servlet类更改应用程序重新启动。

For example j2ee application servers like Tomcat and others have a auto load feature where in as soon as deployment descriptor changes or servlet class changes the application restarts.

您可以使用这些服务器的库,因为大多数tomcat的代码是可重用的和开源的。

You can use the libraries from such servers as most of the code of tomcat is reusable and opensource.

这篇关于Java中的文件更改监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆