import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
public class PropertieUtil {
private static PropertieUtil instance = null;
private PropertieUtil() {
}
public static PropertieUtil getInstance() {
if (instance == null) {
instance = new PropertieUtil();
}
return instance;
}
/**
* 根据传入的资源文件相对于classes路径,加载资源文件到HashMap
* */
public HashMap<String, String> getProperties(String name) {
HashMap<String, String> hm = new HashMap<String, String>();
try {
InputStream is = getClass().getResourceAsStream(name);
Properties pro = new Properties();
pro.load(is);
Enumeration<?> e = pro.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = pro.getProperty(key);
hm.put(key, value);
}
} catch (IOException e) {
e.printStackTrace();
}
return hm;
}
}
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
public class PropertieUtil {
private static PropertieUtil instance = null;
private PropertieUtil() {
}
public static PropertieUtil getInstance() {
if (instance == null) {
instance = new PropertieUtil();
}
return instance;
}
/**
* 根据传入的资源文件相对于classes路径,加载资源文件到HashMap
* */
public HashMap<String, String> getProperties(String name) {
HashMap<String, String> hm = new HashMap<String, String>();
try {
InputStream is = getClass().getResourceAsStream(name);
Properties pro = new Properties();
pro.load(is);
Enumeration<?> e = pro.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = pro.getProperty(key);
hm.put(key, value);
}
} catch (IOException e) {
e.printStackTrace();
}
return hm;
}
}