java项目载入属性文件 要在项目加载前进行配置读入 并且一次性转换为静态变量方式需要用到static静态代码块
注意:test.class为当前class名称,test.properties为属性文件
static {
//加载配置文件hbase.properties
InputStream is = test.class.getResourceAsStream("/test.properties");
Properties props = new Properties();
try {
props.load(is);
} catch (IOException e) {
e.printStackTrace();
}
}
获取属性方式 key为属性文件的key
String testvalue = props.getProperty("key");