import java.util.Properties;
public class ConfigReader {
private static Properties cache = new Properties();
static{
try {
cache.load(ConfigReader .class.getClassLoader().getResourceAsStream("config.properties"));
} catch (Exception e) {
e.printStackTrace();
}
}
static String getValue(String key){
return cache.getProperty(key);
}
}
---------------配置文件内容--------------------------------
name=kelvin
age=23
---------------------------------------------------------------
另见:http://hi.baidu.com/xxiaomazha/blog/item/a3ad32df5c066b5d95ee37f5.html
http://hi.baidu.com/ytstudio/blog/item/855e09a9a41ba8ff1e17a238.html xml读取和写入