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 閱讀(300) 評論(0)  編輯  收藏 所屬分類: Java錯誤解決經驗Java 技術

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


          網站導航:
           
          主站蜘蛛池模板: 陕西省| 渝中区| 大姚县| 册亨县| 游戏| 绥德县| 定安县| 马公市| 昌邑市| 玉屏| 沁水县| 林甸县| 黎平县| 腾冲县| 专栏| 濮阳县| 宣威市| 凤凰县| 黎平县| 双牌县| 昂仁县| 册亨县| 烟台市| 萝北县| 达日县| 中江县| 凤台县| 蒲城县| 马山县| 明星| 永胜县| 孝义市| 乡城县| 枣强县| 钟山县| 楚雄市| 阿合奇县| 汾阳市| 资溪县| 云阳县| 毕节市|