hyljava

          JavaSE讀取Properties文件的六種方法

          使用JavaSEAPI讀取Properties文件的六種方法

           

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

          示例:InputStreamin=lnewBufferedInputStream(newFileInputStream(name));

          Propertiesp=newProperties();

          p.load(in);

           

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

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

           

          3。使用java.util.PropertyResourceBundle類的構造函數

          示例:InputStreamin=newBufferedInputStream(newFileInputStream(name));

          ResourceBundlerb=newPropertyResourceBundle(in);

           

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

          示例:InputStreamin=JProperties.class.getResourceAsStream(name);

          Propertiesp=newProperties();

          p.load(in);

           

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

          示例:InputStreamin=JProperties.class.getClassLoader().getResourceAsStream(name);

          Propertiesp=newProperties();

          p.load(in);

           

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

          示例:InputStreamin=ClassLoader.getSystemResourceAsStream(name);

          Propertiesp=newProperties();

          p.load(in);

          補充

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

          示例:InputStreamin=context.getResourceAsStream(path);

          Propertiesp=newProperties();

          p.load(in);

          posted on 2012-11-16 15:24 何云隆 閱讀(1430) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 刚察县| 保德县| 德江县| 宽甸| 扬州市| 桑日县| 宜城市| 石首市| 丰原市| 渝中区| 斗六市| 杭锦后旗| 托克逊县| 沙河市| 兖州市| 济阳县| 三明市| 芦溪县| 安徽省| 扎赉特旗| 平山县| 永昌县| 苗栗县| 习水县| 老河口市| 临江市| 大同县| 旅游| 当阳市| 江城| 上栗县| 共和县| 浮山县| 蒙山县| 手机| 崇礼县| 泰宁县| 衡阳县| 攀枝花市| 历史| 新竹市|