把文件以字节流的形式读入内存;
Properties props = new Properties();
try {
* Reads a property list (key and element pairs) from the input byte stream.
* The input stream is in a simple line-oriented format
props.load(is);
} catch (IOException e) {
logger.error("加载properties配置文件错误:", e);
//e.printStackTrace();
}
Properties 继承了 HashTable;也是以键值对的形式存放数据的
再使用 Properties类中的getProperty方法获得需要的那个键值对的值
public String getProperty(String key) {
Object oval = super.get(key);
String sval = (oval instanceof String) ? (String)oval : null;
return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;
}