Sunspl

          Hello,everyone,i am sun. 天道酬勤,笨鳥先飛.
          隨筆 - 47, 文章 - 0, 評論 - 24, 引用 - 0
          數據加載中……

          J2SE API讀取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 2006-07-17 13:43 JavaSuns 閱讀(209) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 新泰市| 泉州市| 宁远县| 白沙| 嫩江县| 旬邑县| 乐陵市| 罗甸县| 高台县| 霍林郭勒市| 泸州市| 施秉县| 玛沁县| 乡宁县| 阿城市| 鄂伦春自治旗| 深圳市| 韶山市| 广宁县| 佳木斯市| 青浦区| 邢台县| 九龙县| 穆棱市| 新宾| 林州市| 拜泉县| 贡觉县| 宁陵县| 阿拉尔市| 德庆县| 台安县| 山东省| 共和县| 同江市| 祁门县| 宜阳县| 剑阁县| 谢通门县| 嘉义县| 柞水县|