public static Map<String,String> getPropertiesConfig() throws Exception{
Map<String, String> dataMap = new HashMap<String, String>();
Properties prop = new Properties();
InputStream in = null;
try {
in = 类名.class.getClassLoader().getResourceAsStream("dbconfig.properties");
prop.load(in);
Iterator<String> it = prop.stringPropertyNames().iterator();
while (it.hasNext()) {
String key = it.next();
dataMap.put(key, prop.getProperty(key));
}
} catch (Exception e) {
throw e;
}finally {
if(in != null)
in.close();
}
return dataMap;
Map<String, String> dataMap = new HashMap<String, String>();
Properties prop = new Properties();
InputStream in = null;
try {
in = 类名.class.getClassLoader().getResourceAsStream("dbconfig.properties");
prop.load(in);
Iterator<String> it = prop.stringPropertyNames().iterator();
while (it.hasNext()) {
String key = it.next();
dataMap.put(key, prop.getProperty(key));
}
} catch (Exception e) {
throw e;
}finally {
if(in != null)
in.close();
}
return dataMap;
}
通过此方法可获取到属性文件里给定的名字的值: 上面的类名.getPropertiesConfig().get("Key");