關(guān)于工廠模式的配置文件代碼的問(wèn)題
//讀取配置文件,單例模式
public class PropertiesReader {
? ?private static Map<String,String> map = null;
? ?private PropertiesReader(){}
? ?public static Map<String,String> getProperties(){
? ? ? ?if(map == null){
? ? ? ? ? ?map = new HashMap<>();
? ? ? ? ? ?Properties properties = new Properties();
// ? ? ? ?InputStream in = getClass().getResourceAsStream("type.properties");
? ? ? ? ? ?InputStream in = PropertiesReader.class.getResourceAsStream("type.properties");
? ? ? ? ? ?try {
? ? ? ? ? ? ? ?properties.load(in);
? ? ? ? ? ? ? ?Enumeration en = properties.propertyNames();
? ? ? ? ? ? ? ?while (en.hasMoreElements()){
? ? ? ? ? ? ? ? ? ?String key = (String) en.nextElement();
? ? ? ? ? ? ? ? ? ?String value = properties.getProperty(key);
? ? ? ? ? ? ? ? ? ?map.put(key,value);
? ? ? ? ? ? ? ?}
? ? ? ? ? ?} catch (IOException e) {
? ? ? ? ? ? ? ?e.printStackTrace();
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?return map;
? ?}
}
請(qǐng)問(wèn),這段代碼是固定的嗎?
2017-02-09
type.properties這個(gè)名字是可變化的,其他不變沒(méi)事