夢幻之旅

          DEBUG - 天道酬勤

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

          公告

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

          常用鏈接

          留言簿(21)

          隨筆分類(644)

          隨筆檔案(669)

          文章檔案(6)

          最新隨筆

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          package org.siyn.util;

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

          /**
           * <p>
           * 本類用提供一個線程同步的方法,讀取資源文件中的配置信息
           * </p>
           * 
           * 
          @author siyn
           * @date 2008-7-10
           
          */
          public class PropertiesReader
          {
              
          private String     file;
              
              
          private Properties properties;
              
              
          /**
               * 構(gòu)造 PropertysReader
               * 
          @param {String} path 相對于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對應(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對應(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 閱讀(267) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 阿图什市| 清镇市| 庄河市| 阳城县| 洛南县| 丁青县| 日照市| 温泉县| 宜兰市| 蒙自县| 玉溪市| 晋州市| 临清市| 天门市| 和静县| 剑川县| 景洪市| 芦山县| 铜山县| 怀宁县| 太仓市| 稷山县| 察隅县| 禹城市| 包头市| 治多县| 贵定县| 湖北省| 文水县| 固始县| 嘉善县| 河北省| 梓潼县| 宿松县| 全州县| 江北区| 综艺| 池州市| 花莲县| 德兴市| 大英县|