开发者

JNotify : Supervise a directory all the time

开发者 https://www.devze.com 2023-01-06 15:36 出处:网络
In my project, I use some files in a directory. And for some reasons, I must load the file开发者_Go百科s at the launch of the project, and if there is an action on these files, I must reload them (in

In my project, I use some files in a directory. And for some reasons, I must load the file开发者_Go百科s at the launch of the project, and if there is an action on these files, I must reload them (in a HashMap) For the moment, I load them just at the moment of the use, but I want to do this at the load of application, and let the JNotify working all the time.

I am working on a web project. Can I have some help please ? thnx


Other than manually polling the file system yourself, JNotify (or a library like it) is probably your best option for now. There are changes planned for Java 7 that will address the need for this (see the WatchService section on the linked page).

Edit:

On closer reading of your question, I understand that you're not really looking for alternatives, but for help in using JNotify. See the code samples section. You need to add a watch to the directory or files you're watching, and add your own class as a Listener for change events. You'll need to implement JNotifyListener in your code and handle the events that you're interested in.


I used a Servlet that I launch in the begining of the application. I create the JNotify in the init() method, and because it have Listeners, it will listen to the directories that I want to watch all the life of the Servlet. Thnx for you answers.

0

精彩评论

暂无评论...
验证码 换一张
取 消