<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
    不錯
    主站蜘蛛池模板: 国产亚洲精品成人久久网站| 久久国产乱子精品免费女| 精品国产亚洲男女在线线电影| 国内精品免费在线观看| 四虎亚洲精品高清在线观看| 久久久久国产亚洲AV麻豆| 四虎永久在线观看免费网站网址| 猫咪免费观看人成网站在线| 18gay台湾男同亚洲男同| 国产免费人人看大香伊| 24小时免费看片| 羞羞视频免费网站日本| 亚洲1区1区3区4区产品乱码芒果 | 亚洲综合在线视频| 国产成人综合久久精品免费| 香蕉成人免费看片视频app下载| 久久亚洲色WWW成人欧美| 亚洲AV日韩AV永久无码绿巨人| 四虎影视在线永久免费观看| 亚洲视频在线免费播放| 曰韩无码AV片免费播放不卡 | 美女又黄又免费的视频| 亚洲无成人网77777| 国产精品亚洲w码日韩中文| 91九色视频无限观看免费| 久久成人永久免费播放| 亚洲av永久无码一区二区三区| 久久久久亚洲AV无码麻豆| 亚洲一本大道无码av天堂| 日本一区二区三区日本免费| 最近免费中文字幕大全免费 | 黄页网站在线免费观看| 亚洲色中文字幕在线播放| 亚洲视频精品在线观看| 亚洲精品乱码久久久久久蜜桃不卡 | 亚洲精品国产精品国自产网站| 亚洲AV午夜福利精品一区二区| 亚洲国产精品狼友中文久久久| a级毛片无码免费真人| 5555在线播放免费播放| 久草福利资源网站免费|