hk2000c技術專欄

          技術源于哲學,哲學來源于生活 關心生活,關注健康,關心他人

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            111 隨筆 :: 1 文章 :: 28 評論 :: 0 Trackbacks
           

          使用J2SEAPI讀取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 2007-12-27 00:00 hk2000c 閱讀(301) 評論(0)  編輯  收藏 所屬分類: Java錯誤解決經驗 、Java 技術

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


          網站導航:
           
          主站蜘蛛池模板: 读书| 德钦县| 张家川| 平阳县| 韶山市| 庐江县| 綦江县| 濮阳市| 留坝县| 巴彦淖尔市| 庆安县| 湖南省| 泰宁县| 莒南县| 大丰市| 崇阳县| 临沂市| 海原县| 蒲城县| 重庆市| 辰溪县| 大庆市| 怀化市| 包头市| 巴青县| 抚远县| 黄大仙区| 宁陵县| 都安| 荥阳市| 桃园县| 汉川市| 东海县| 汉中市| 石林| 平定县| 辽宁省| 恩平市| 平武县| 阳东县| 京山县|