<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 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    Apache Commons Configuration簡(jiǎn)介

    Posted on 2011-06-09 14:56 瘋狂 閱讀(4221) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): apache項(xiàng)目
    使用Commons  Configuration可以很好的管理我們的配置文件的讀寫(xiě),官網(wǎng):http://commons.apache.org/configuration/
    它支持對(duì)配置文件的讀取,保存,運(yùn)行期加載,操作非常方便。下面簡(jiǎn)單的一下代碼示例一下,具體的其他操作文檔可以去官方找到:
    需要用到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));
            
    //設(shè)置自動(dòng)保存 或顯示調(diào)用 config.save();
            config.setProperty("colors.background""#000000");
            config.setAutoSave(
    true);
        }

        
    //運(yùn)行期參數(shù)修改加載
        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);//在休眠期間,手動(dòng)修改文件里面的url值后觀(guān)察日志情況
            System.out.println(config.getString("url"));
        }

    }

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

    評(píng)論

    # re: Apache Commons Configuration簡(jiǎn)介  回復(fù)  更多評(píng)論   

    2011-06-15 23:43 by RunCode
    不錯(cuò)
    主站蜘蛛池模板: 国产大片线上免费观看| 污视频在线免费观看| 日韩免费观看视频| 亚洲最大天堂无码精品区| 亚洲人成免费网站| 亚洲日韩乱码中文无码蜜桃臀| 一级毛片在线观看免费| 日产亚洲一区二区三区| 1a级毛片免费观看| 亚洲国产成+人+综合| 在线a级毛片免费视频| 国产成人亚洲综合一区 | 无码国产精品一区二区免费vr| 亚洲精品tv久久久久久久久| 国色精品va在线观看免费视频 | 亚洲第一页在线视频| 亚洲精品在线免费看| 亚洲中文字幕一二三四区苍井空| 最近最新中文字幕完整版免费高清| 亚洲午夜精品一区二区麻豆| 免费国产美女爽到喷出水来视频| 九九久久精品国产免费看小说 | 亚洲欧洲久久久精品| 久久久久久免费一区二区三区| 久久亚洲日韩看片无码| 久久精品a一国产成人免费网站 | 中文字幕成人免费高清在线| 久久亚洲AV无码精品色午夜| 毛片A级毛片免费播放| 免费一级做a爰片久久毛片潮| 亚洲熟妇无码八AV在线播放| 0588影视手机免费看片| 亚洲AV无码AV吞精久久| 中文字幕精品亚洲无线码一区 | 精品亚洲一区二区三区在线播放| 无码日韩精品一区二区免费暖暖| 亚洲人配人种jizz| 一级毛片直播亚洲| 99久久免费精品高清特色大片| 亚洲AV无码AV男人的天堂不卡| 亚洲国产精品无码久久一线|