----------------------------------通过Properties类读取-----------------------------------/**
* 通过Properties类读取属性文件
* @param strPath 属性文件路径
*/
private void ReadPropertyFile(String strPath){
try {
Properties pro = new Properties(); //Properties继承自Hashtable
//pro.load(new FileInputStream(new File(strPath))); //文件不在项目的src文件夹
pro.load(this.getClass().getResourceAsStream(strPath)); //文件在项目的src文件夹
Iterator<Object> iterator = pro.keySet().iterator();
while(iterator.hasNext()){
String key = iterator.next().toString();
String value = pro.getProperty(key);
}
} catch (Exception e) {
e.printStackTrace();
}
}
-------------------------------通过ResourceBundle类读取-----------------------------/**
* 通过ResourceBundle类读取属性文件
* @param strPath 属性文件路径
*/
private void ReadPropertyFile(String strPath){
ResourceBundle sourceBundle = ResourceBundle.getBundle(strPath);
String value = sourceBundle.getString(key);
}