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 技術

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


          網站導航:
           
          主站蜘蛛池模板: 元阳县| 涟源市| 宝坻区| 宝应县| 益阳市| 彭水| 鄂托克前旗| 高陵县| 离岛区| 华容县| 封开县| 澄城县| 罗平县| 高陵县| 六枝特区| 哈巴河县| 青龙| 晋州市| 岫岩| 隆昌县| 蕲春县| 林甸县| 白城市| 密山市| 秦安县| 忻城县| 郑州市| 大丰市| 本溪| 缙云县| 崇信县| 新沂市| 新竹县| 扎赉特旗| 岳池县| 昭通市| 杭锦旗| 杭州市| 唐河县| 阿坝县| 巴彦淖尔市|