通过下面的方法,把*.properties文件中的数据读取到Map里面!
import java.util.Properties;
/*** properties文件的读取工具
*
*/
public class PropertiesReaderUtil {
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);
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
}
注意:type.properties中数据是以键值对存储的,
例如:
left=com.sunny.project.LeftHair
right=com.sunny.project.RightHair