第一种:
private static Properties prop = new Properties();
static{
try {
prop.load(MyContext.class.getClassLoader().getResourceAsStream("interface.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 根据 keyCode 获取properties 文件的值
* @param keyCode
* @return
*/
public static String getUrlByKey(String keyCode){
return prop.getProperty(keyCode);
}
其中MyContext是所在的类。
第二种:
public static ResourceBundle config = ResourceBundle
.getBundle("config");
properties读取的几种方法
原文:http://www.cnblogs.com/yanduanduan/p/4882458.html