<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    瘋狂

    STANDING ON THE SHOULDERS OF GIANTS
    posts - 481, comments - 486, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    Apache Commons Configuration簡介

    Posted on 2011-06-09 14:56 瘋狂 閱讀(4209) 評論(1)  編輯  收藏 所屬分類: apache項目
    使用Commons  Configuration可以很好的管理我們的配置文件的讀寫,官網:http://commons.apache.org/configuration/
    它支持對配置文件的讀取,保存,運行期加載,操作非常方便。下面簡單的一下代碼示例一下,具體的其他操作文檔可以去官方找到:
    需要用到commons-lang,commons-collections,commons-logging,log4j jar包
    public class Test {
        
        
    public static  void main(String[] args) throws ConfigurationException, InterruptedException {
            xmlLoadTest();
            fileLoadTest();
            saveTest();
            runtimeReload();
        }

        
    //xml文件
        public static void xmlLoadTest() throws ConfigurationException{
            String file 
    = "test1.xml";
            XMLConfiguration config 
    = new XMLConfiguration(Test.class.getResource(file));
            System.out.println(config.getString(
    "conf.url"));
            System.out.println(config.getDouble(
    "conf.money"));
        }
      
        
    //properties文件
        private static void fileLoadTest() throws ConfigurationException {
            String file 
    = "test2.properties";
            PropertiesConfiguration config 
    = new PropertiesConfiguration(Test.class.getResource(file));
            System.out.println(config.getString(
    "url"));
        }

        
    //保存到文件
        public static void saveTest() throws ConfigurationException{
            String file 
    = "test2.properties";
            PropertiesConfiguration config 
    = new PropertiesConfiguration(Test.class.getResource(file));
            
    //設置自動保存 或顯示調用 config.save();
            config.setProperty("colors.background""#000000");
            config.setAutoSave(
    true);
        }

        
    //運行期參數修改加載
        public static void runtimeReload() throws ConfigurationException, InterruptedException{
            String file 
    = "test2.properties";
            PropertiesConfiguration config 
    = new PropertiesConfiguration(Test.class.getResource(file));
            config.setReloadingStrategy(
    new FileChangedReloadingStrategy());
            System.out.println(config.getString(
    "url"));
            Thread.sleep(
    10000);//在休眠期間,手動修改文件里面的url值后觀察日志情況
            System.out.println(config.getString("url"));
        }

    }

    Configuration 的參數可能來自下面的資源: 
         Properties files XML documents,Property list files (.plist),JNDI,JDBC Datasource,System properties, Applet parameters,Servlet parameters

    評論

    # re: Apache Commons Configuration簡介  回復  更多評論   

    2011-06-15 23:43 by RunCode
    不錯
    主站蜘蛛池模板: 无套内谢孕妇毛片免费看看| 91成人免费观看网站| 免费高清在线爱做视频| 亚洲乱码卡一卡二卡三| 亚洲狠狠色丁香婷婷综合| 国产高潮流白浆喷水免费A片 | 曰批全过程免费视频网址| 国产一区二区三区在线免费| 91麻豆精品国产自产在线观看亚洲| 99ri精品国产亚洲| 黄网站在线播放视频免费观看| 在线观看免费宅男视频| 久久亚洲精品成人| 午夜网站在线观看免费完整高清观看| 亚洲狠狠婷婷综合久久久久| 亚洲免费综合色在线视频| 在线视频免费观看www动漫| 亚洲AV一区二区三区四区| 俄罗斯极品美女毛片免费播放| 久久久无码精品亚洲日韩按摩| 午夜精品射精入后重之免费观看| 亚洲美女色在线欧洲美女| 国产V片在线播放免费无码| 国产综合亚洲专区在线| 久久免费动漫品精老司机| 亚洲制服丝袜第一页| 久久久高清日本道免费观看| 亚洲AV无码精品无码麻豆| 色播精品免费小视频| 青草久久精品亚洲综合专区| 亚洲中文无韩国r级电影| 男人j进入女人j内部免费网站| 亚洲伊人色一综合网| 国产一区二区免费在线| 黄色免费在线网站| 国产午夜亚洲精品| 亚洲国产精品专区在线观看| 国产精品久久亚洲一区二区| 久久WWW免费人成人片| 特级毛片在线大全免费播放| 亚洲专区在线视频|