package com.utils;
import java.io.InputStream;
import java.util.Properties;
/**
* 文件数值获取
*/
public class PropertyValues {
public static Properties properties;
static {
loadPropertyValue();
}
public static void loadPropertyValue(){
InputStream inputStream=null;
inputStream= PropertyValues.class.getClassLoader().getResourceAsStream("wsData.properties");
//若配置文件中有中文的话需要做以下配置
因为.propertis文件中的中文是字节流,中文读取需要转换成字符流才能正常读取
//==start
BufferedReader bufferedReader=new BufferedReader(new
InputStreamReader(inputStream));
//=====end=======
properties=new Properties();
try {
properties.load(inputStream);
}catch (Exception e){
System.out.println("get value failed!");
}finally {
try {
inputStream.close();
}catch (Exception e){
System.out.println("IO close exception!");
}
}
}
public static String getPropertyValue(String key){
if (properties==null){
loadPropertyValue();
}
return properties.getProperty(key);
}
}