package test;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
/**
* 异常分析器,该类维护着一个properties对象,对于该对象的定义在根目录下的exceptionDefine.properties中
*
*/
public class PropertiesAnalyzer {
private static Properties MyProperties = new Properties();
static{
try {
MyProperties.load(new InputStreamReader(PropertiesAnalyzer.class.getResourceAsStream("/myProperties.properties"), "utf-8"));
} catch (IOException e) {
e.printStackTrace();
System.out.println("错误:properties初始化失败,请检查后重新启动应用");
}
}
/**
* 通过传入的string参数获得和这个string对应的值
* @param string
* @return 参数string对应的值, 如果没有默认值为-1
*/
public static String getValue(String string){
String value = MyProperties.getProperty(string);
if(value == null){
return "-1";
}
return value;
}
public static void main(String[] args) {
System.out.println(PropertiesAnalyzer.getValue("测试数据"));
}
}
///
//myProperties.properties
//测试数据=hello world!你好 世界!
//输出:hello world!你好 世界!