<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亚洲自偷在线观看国产馆| 亚洲中文字幕伊人久久无码| 亚洲精品午夜在线观看| 久久aⅴ免费观看| 亚洲成A人片在线观看WWW| 国产午夜不卡AV免费| 亚洲AV本道一区二区三区四区 | 18观看免费永久视频| 老汉色老汉首页a亚洲| 日本片免费观看一区二区| 亚洲精品人成网在线播放影院| 国产精品成人免费视频网站京东 | 精品免费久久久久久久| 两个人看的www免费高清| 精品亚洲综合久久中文字幕| 全亚洲最新黄色特级网站 | 美女在线视频观看影院免费天天看| 亚洲精品视频在线播放| 亚洲国产一成人久久精品| 亚洲免费在线观看视频| 色欲A∨无码蜜臀AV免费播| 日韩电影免费在线观看网站| sihu国产精品永久免费| 亚洲AV无码一区二区二三区软件| 麻豆一区二区免费播放网站| 美女视频黄频a免费观看| 国产亚洲美女精品久久久久狼 | 无码 免费 国产在线观看91| 亚洲AV永久纯肉无码精品动漫| 久久精品国产亚洲Aⅴ蜜臀色欲| 最近免费中文字幕大全免费版视频| 亚洲丁香婷婷综合久久| 亚洲人成色77777在线观看大| 99久久精品日本一区二区免费| 一级A毛片免费观看久久精品 | 国产成人亚洲精品影院| 亚洲欧洲日本在线| 久久精品国产亚洲精品| 亚洲欧洲∨国产一区二区三区| 国产精品视频免费一区二区| 69成人免费视频无码专区|