課程
/后端開發(fā)
/Java
/模式的秘密——工廠模式
那個(gè)Properties類的實(shí)現(xiàn)代碼,老師可不可以給出來(lái)???或者告訴我們到那里可以找到???!?。?/p>
2014-12-21
源自:模式的秘密——工廠模式 2-1
正在回答
Iterator
package?com.factory; import?java.io.InputStream; import?java.io.UnsupportedEncodingException; import?java.util.Enumeration; import?java.util.HashMap; import?java.util.Map; import?java.util.Properties; import?javax.xml.stream.events.EndElement; /**? ?*?properties文件讀取? ?*/?? public?class?PropertiesReader?{?? ?????? ????/**? ?????*?此方法只支持讀取src目錄property文件? ?????*?@param?name?? ?????*?@return? ?????*?@throws?UnsupportedEncodingException? ?????*/?? ????public?Map<String,?String>?getProperties(){?? ???? ???? Properties?props?=?new?Properties(); ???? Map<String,?String>?map?=?new?HashMap<String,?String>(); ???? ???? try?{ ???????? InputStream?in?=?getClass().getResourceAsStream("type.properties"); ???????? props.load(in); ???????? Enumeration?en?=?props.propertyNames(); ???????? while(en.hasMoreElements()){ ???????? String?key?=?(String)?en.nextElement(); ???????? String?property?=?props.getProperty(key); ???????? map.put(key,?property); ???????? System.out.println(key+"?"+property); ???????? } }?catch?(Exception?e)?{ e.printStackTrace(); } ???? return?map; ???? ????}?? }
很快會(huì)提供源碼的。
舉報(bào)
本課程即將講解Java中的工廠模式和抽象工廠模式的應(yīng)用
1 回答properties配置資料
1 回答關(guān)于工廠模式的配置文件代碼的問(wèn)題
3 回答new LeftHair() 實(shí)例化,然后引用的類型為HairInterface,開發(fā)中這樣做有什么意義 ?
1 回答getClass().getResourceAsStream("type.properties); 中g(shù)etResourceAsStream()是哪個(gè)類的方法?
3 回答用反射去獲取對(duì)象,為什么在測(cè)試類中測(cè)試的時(shí)候一直報(bào)類型轉(zhuǎn)換錯(cuò)誤
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-05-08
Iterator
2016-12-07
2014-12-23
很快會(huì)提供源碼的。