posts - 495,comments - 227,trackbacks - 0

            使用J2SE API讀取Properties文件的六種方法:

            1.使用Java.util.Properties類的load()方法

            示例:


                InputStream in = lnew BufferedInputStream(new FileInputStream(name));
          Properties p = new Properties();
          p.load(in);

            2.使用java.util.ResourceBundle類的getBundle()方法


          示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());

            3.使用java.util.PropertyResourceBundle類的構(gòu)造函數(shù)


          示例: InputStream in = new BufferedInputStream(new FileInputStream(name));
          ResourceBundle rb = new PropertyResourceBundle(in);

            4.使用class變量的getResourceAsStream()方法


          示例: InputStream in = JProperties.class.getResourceAsStream(name);
          Properties p = new Properties();
          p.load(in);

            5.使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法


          示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);
          Properties p = new Properties();
          p.load(in);

            6.使用java.lang.ClassLoader類的getSystemResourceAsStream()靜態(tài)方法


          示例: InputStream in = ClassLoader.getSystemResourceAsStream(name);
          Properties p = new Properties();
          p.load(in);

            補(bǔ)充

            Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法


          示例:InputStream in = context.getResourceAsStream(path);
          Properties p = new Properties();
          p.load(in);

            

          posted on 2009-08-13 11:19 SIMONE 閱讀(439) 評(píng)論(0)  編輯  收藏 所屬分類: JAVA 、JSP
          主站蜘蛛池模板: 抚州市| 太仆寺旗| 汝阳县| 阿克苏市| 博乐市| 万载县| 玉溪市| 阳曲县| 铜山县| 忻城县| 河曲县| 武城县| 昌吉市| 南昌县| 嘉荫县| 吉隆县| 镇康县| 孟村| 墨竹工卡县| 当阳市| 仙游县| 阳信县| 牙克石市| 潍坊市| 邢台市| 广安市| 姜堰市| 治多县| 寿光市| 景东| 桂阳县| 循化| 东乡县| 周至县| 景德镇市| 得荣县| 都江堰市| 新绛县| 上犹县| 灵宝市| 琼海市|