在开发应用时须要在properties文件里面写一个开关,手动禁用或启用程序的某项功能。百度了下,大部分人认为不可能实现此功能,还说了不少原理。不罗嗦,直接说解决方案。spa
我是使用jfinal来开发的,所以下面的代码片断,基于jfinal的prokit等文件的修改。开发
PropertiesConfiguration cfg = new PropertiesConfiguration(fileName);get
cfg.setReloadingStrategy(new FileChangedReloadingStrategy());it
cfg.setEncoding(encoding);io
cfg.load();原理
Iterator<String> iterator = cfg.getKeys();百度
properties = new Properties();coding
while(iterator.hasNext()){file
String key = iterator.next();程序
properties.setProperty(key,cfg.getString(key));
}
注:以上代码须要commons-lang2.6 和commons-configuartion1.10 的支持。