使用Java自动重新加载更改的文件 [英] Auto-reload changed files in Java

查看:138
本文介绍了使用Java自动重新加载更改的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多配置文件可以修改应用程序的行为。我希望能够进行更改,并在保存文件时立即反映到应用程序中。有没有一个Java库来帮助这个?



我可以简单地保留一个文件列表与他们的时间戳,并不断检查后台线程时间戳的变化。似乎不太难,但也许有一个更有效的方法来做到这一点?自定义触发器,当某些属性已经改变会很好。

我使用Spring 3.1,是否有一个内置的机制或解决方案,很好地与春天?显然,JDK7现在通过它的 Watch Service API :大多数文件系统实现都具有对文件更改通知的原生支持。但是,如果文件系统不支持这种机制,Watch服务将轮询文件系统,等待事件发生。所以,这将是我转移到JDK7的动力。



http://commons.apache.org/配置/ userguide / howto_filebased.html


I have a lot of configuration files that modify how my application behaves. I want to be able to make a change and it gets reflected in the application right away when saving the file. Is there a Java library to help with this?

I could simply keep a list of files with their timestamps and continuously check in a background thread when a timestamp changes. Doesn't seem too difficult, but maybe there's a more efficient way to do this? Custom triggers when certain properties have changed would be nice.

I'm using Spring 3.1, is there a built-in mechanism or solution which works nicely with Spring?

UPDATE: Apparently JDK7 now includes this functionality through its Watch Service API: "Most file system implementations have native support for file change notification. The Watch Service API takes advantage of this support where available. However, when a file system does not support this mechanism, the Watch Service will poll the file system, waiting for events." So this'll be my motivation to migrate to JDK7.

解决方案

Edited:

http://commons.apache.org/configuration/userguide/howto_filebased.html

这篇关于使用Java自动重新加载更改的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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