夢(mèng)幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評(píng)論 :: 0 Trackbacks
          <2008年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          公告

          本博客中未注原創(chuàng)的文章均為轉(zhuǎn)載,對(duì)轉(zhuǎn)載內(nèi)容可能做了些修改和增加圖片注釋,如果侵犯了您的版權(quán),或沒有注明原作者,請(qǐng)諒解

          常用鏈接

          留言簿(21)

          隨筆分類(644)

          隨筆檔案(669)

          文章檔案(6)

          最新隨筆

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          package org.siyn.util;

          import java.io.InputStream;
          import java.util.Properties;

          /**
           * <p>
           * 本類用提供一個(gè)線程同步的方法,讀取資源文件中的配置信息
           * </p>
           * 
           * 
          @author siyn
           * @date 2008-7-10
           
          */
          public class PropertiesReader
          {
              
          private String     file;
              
              
          private Properties properties;
              
              
          /**
               * 構(gòu)造 PropertysReader
               * 
          @param {String} path 相對(duì)于classes的文件路徑
               
          */
              
          public PropertiesReader(String path)
              {
                  
          this.file = path;
                  
          this.properties = new Properties();
              }
              
              
          /**
               * <p>
               * 本方法根據(jù)資源名獲取資源內(nèi)容
               * <p>
               * 
               * 
          @param {String} key 資源文件內(nèi)key
               * 
          @param {Stirng} defaultValue 默認(rèn)值
               * 
               * @reaurn String key對(duì)應(yīng)的資源內(nèi)容
               
          */
              
          public synchronized String getProperty(String key, String defaultValue)
              {
                  
          try
                  {
                      InputStream in 
          = this.getClass().getClassLoader()
                              .getResourceAsStream(
          this.file);
                      
                      properties.load(in);
                      
                  }
                  
          catch (Exception ex1)
                  {
                      System.out.println(
          "沒有找到資源文件:" + this.file);
                  }
                  
          return properties.getProperty(key, defaultValue);
              }
              
              
          /**
               * <p>
               * 本方法根據(jù)資源名獲取資源內(nèi)容
               * <p>
               * 
               * 
          @param {String} key 資源文件內(nèi)key
               * 
          @param {Stirng} defaultValue 默認(rèn)值
               * 
          @param {boolean} isnull 如果配置文件value為空,是否使用默認(rèn)值
               * 
               * @reaurn String key對(duì)應(yīng)的資源內(nèi)容
               
          */
              
          public synchronized String getProperty(String key, String defaultValue,boolean isnull)
              {
                  String value 
          = null;
                  value 
          = getProperty(key,defaultValue);
                  
          if(isnull && value == null && "".equals(value.trim()) )
                      value 
          = defaultValue;
                  
          return value;
              }
              
              
          public static void main(String[] args)
              {
                  PropertiesReader preader 
          = new PropertiesReader("log4j.properties");
                  String rootLogger 
          = preader.getProperty("aaa""defaul");
                  System.out.println(rootLogger);
              }
          }
          posted on 2008-07-21 14:48 HUIKK 閱讀(270) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 新密市| 三都| 绥德县| 新绛县| 东丰县| 巴林左旗| 陵水| 丰镇市| 茂名市| 丹巴县| 伊宁县| 吴江市| 万山特区| 青海省| 田阳县| 元阳县| 镇原县| 奉节县| 濮阳市| 江阴市| 大庆市| 志丹县| 孝昌县| 泉州市| 大洼县| 连南| 郯城县| 黔东| 梧州市| 务川| 荔浦县| 绍兴市| 凤凰县| 二手房| 黄冈市| 汨罗市| 申扎县| 甘肃省| 衡水市| 阜南县| 明溪县|