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 何云隆 閱讀(1428) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 紫阳县| 杭锦后旗| 大洼县| 繁峙县| 达日县| 商城县| 仁化县| 白玉县| 普洱| 湾仔区| 通化县| 黄骅市| 秀山| 肇庆市| 临澧县| 宁阳县| 偏关县| 广州市| 平和县| 彭阳县| 威海市| 五家渠市| 游戏| 庐江县| 恩施市| 咸阳市| 湖口县| 洪湖市| 瑞丽市| 商洛市| 密云县| 左云县| 上饶市| 北海市| 安顺市| 商洛市| 威信县| 凌云县| 南平市| 格尔木市| 徐闻县|