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

          主站蜘蛛池模板: 桦川县| 霍邱县| 新干县| 县级市| 福贡县| 东平县| 米泉市| 芜湖县| 包头市| 兴国县| 邵阳县| 拉孜县| 喀喇| 博野县| 东至县| 临沭县| 上栗县| 绍兴市| 宁城县| 鸡东县| 马公市| 什邡市| 花垣县| 锦州市| 新巴尔虎右旗| 长武县| 石台县| 敦化市| 靖边县| 井冈山市| 东港市| 徐闻县| 沈阳市| 湖南省| 巴马| 集贤县| 襄城县| 清涧县| 新竹市| 壶关县| 桓台县|