<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 22, comments - 17, trackbacks - 0, articles - 15
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    讀取properties的幾種方法

    Posted on 2006-12-02 16:16 碼農(nóng)cz 閱讀(316) 評論(0)  編輯  收藏 所屬分類: OtherJava

    1.

    ?1?private?void?getContextParam(){
    ?2???InputStream?is=this.getClass().getClassLoader().getResourceAsStream("clientConfig.properties");
    ?3???Properties?prop=?new?Properties();
    ?4???try?{
    ?5????prop.load(is);
    ?6????this.classForName=prop.getProperty("classForName");
    ?7????this.connectStr=prop.getProperty("connectStr");
    ?8????this.userName=prop.getProperty("userName");
    ?9????this.psw=prop.getProperty("psw");
    10???}?catch?(IOException?e)?{
    11????e.printStackTrace();
    12???}
    13??}
    14??//注:只能將clientConfig.properties放入src下
    15?
    16?

    2.
    ?1?String?realName=this.getServletContext().getRealPath("WEB-INF");
    ?2??????Properties?prop=?new?Properties();
    ?3???InputStream?is=null;
    ?4???try?{
    ?5????is?=?new?BufferedInputStream(new?FileInputStream(new?File(realName+"/clientConfig.properties")));
    ?6????prop.load(is);
    ?7???}?catch?(FileNotFoundException?e)?{
    ?8????//logger.info("沒有發(fā)現(xiàn)所需要的配置文件!"+e);
    ?9????e.printStackTrace();
    10???}?catch?(IOException?e)?{
    11????//logger.info("讀取文件的過程中出錯!"+e);
    12????e.printStackTrace();
    13???}
    14?
    15?//注:同樣需要定制文件存放的目錄
    16?
    17?

    3.

    ?1?public?static?String?getValue(String?key)?{
    ?2?
    ?3?private?static?Properties?propertie;
    ?4?
    ?5?String?path?=?(Configuration.class.getResource("/")?+?"").substring(6);
    ?6???Configuration?rc?=?new?Configuration(path?+?"//config.properties");
    ?7???if?(propertie.containsKey(key))?{
    ?8????String?value?=?propertie.getProperty(key);//?得到某一屬性的值
    ?9????return?value;
    10???}?else
    11????return?"";
    12??}
    13?
    14?//注:只適用在windows下,不同的操作系統(tǒng)需要使用File.pathSeparatorChar進(jìn)行分割
    15?

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲精品WWW久久久久久| 国产99久久亚洲综合精品| 一级毛片正片免费视频手机看| 性做久久久久久免费观看| 国产精品无码亚洲精品2021| 亚洲伊人久久综合影院| 国产精品成人免费福利| 久久亚洲欧美国产精品| 亚洲色婷婷综合开心网| 免费人成在线视频| 国产色无码精品视频免费| 美女18毛片免费视频| 相泽亚洲一区中文字幕| 全免费a级毛片免费看| 亚洲国产成人片在线观看| 99热免费在线观看| 亚洲黄色在线视频| 性盈盈影院免费视频观看在线一区| 美女被爆羞羞网站免费| 亚洲桃色AV无码| 亚洲国产成人手机在线电影bd| 亚洲乱亚洲乱妇无码| 日本亚洲欧洲免费天堂午夜看片女人员 | 国产一区在线观看免费| 国产成人免费A在线视频| 免费大黄网站在线观| 亚洲精品天堂成人片?V在线播放| 亚洲午夜国产精品无码| 精品亚洲aⅴ在线观看| 亚洲av无码一区二区三区观看| 亚洲色欲啪啪久久WWW综合网| 亚洲精品色在线网站| 精品久久久久久国产免费了| 中文字幕在线免费观看| 大学生a级毛片免费观看| 国产精品亚洲mnbav网站 | 四虎影库久免费视频| 久久亚洲中文字幕精品一区| 亚洲黄网在线观看| 色九月亚洲综合网| 永久免费视频网站在线观看|