<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ò)
    主站蜘蛛池模板: 国产精品亚洲小说专区| 亚洲精品在线免费观看| 美女尿口扒开图片免费| 亚洲国产成人久久三区| 91久久精品国产免费一区| 亚洲国产精品一区二区久久| 亚洲不卡中文字幕| 特级毛片在线大全免费播放| 99免费在线观看视频| 免费一级毛片不卡在线播放| 久久精品国产亚洲av日韩| 免费精品久久久久久中文字幕| 免费国产人做人视频在线观看| 成年免费a级毛片| 自拍偷自拍亚洲精品情侣| 亚洲最大av资源站无码av网址| 4hu四虎最新免费地址| 亚洲综合日韩久久成人AV| a级毛片视频免费观看| 老色鬼久久亚洲AV综合| 久草免费在线观看视频| 亚洲熟妇自偷自拍另欧美| 四虎影视精品永久免费网站| rh男男车车的车车免费网站 | 99爱在线精品视频免费观看9| 1区1区3区4区产品亚洲| 久青草视频97国内免费影视| 国产国拍亚洲精品mv在线观看 | 免费人成网站在线观看不卡 | 亚洲AV成人片色在线观看高潮| 日本片免费观看一区二区| 久久精品亚洲中文字幕无码网站| 97视频免费观看2区| 亚洲精品123区在线观看| www视频免费看| 春暖花开亚洲性无区一区二区| 亚洲熟妇av一区二区三区漫画| 日本三级2019在线观看免费| 久青草国产免费观看| 中文字幕亚洲精品资源网| 又粗又大又猛又爽免费视频|