Properties类的实现代码!!
那个Properties类的实现代码,老师可不可以给出来啊?或者告诉我们到那里可以找到啊?!!!
那个Properties类的实现代码,老师可不可以给出来啊?或者告诉我们到那里可以找到啊?!!!
2014-12-21
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;
}
}举报