properties文件的读取Util

来源:互联网 发布:高品质音乐软件 编辑:程序博客网 时间:2024/06/07 01:16

通过下面的方法,把*.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


0 0
原创粉丝点击