屬性文件的讀取二法

          Posted on 2006-07-06 18:13 負人博客 閱讀(388) 評論(0)  編輯  收藏 所屬分類: JAVA技術

          1 Properties類直接讀取屬性文件
          ?
          public class Test {
          ?public static void main(String[] args) {
          ??InputStream is = Test.class.getResourceAsStream("nojar.properties");
          ??if (is == null)
          ???System.out.println("文件找不到");
          ??Properties prop = new Properties();
          ??try {
          ???prop.load(is);
          ??} catch(Exception e) {
          ???e.printStackTrace();
          ??}
          ??System.out.println(prop.getProperty("test"));
          ?}
          }
          2 通過ResourceBundle讀取屬性文件

          public class Test {
          ?public static void main(String[] args) {
          ??ResourceBundle rb = ResourceBundle.getBundle("test");
          ??System.out.println(rb.getString("test"));
          ?}
          }


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


          網站導航:
           

          posts - 26, comments - 5, trackbacks - 0, articles - 8

          Copyright © 負人博客

          主站蜘蛛池模板: 柳江县| 天水市| 米泉市| 夏河县| 大埔县| 孟津县| 天柱县| 永年县| 苏尼特左旗| 石林| 辽宁省| 鹿邑县| 宜城市| 博白县| 潍坊市| 钟祥市| 庐江县| 永丰县| 临邑县| 芒康县| 栾川县| 荆门市| 永寿县| 巴青县| 武夷山市| 武胜县| 通河县| 温宿县| 伊川县| 宁强县| 吉安市| 定日县| 达拉特旗| 普格县| 五寨县| 崇明县| 淄博市| 蕲春县| 化州市| 肥城市| 桂东县|