java项目载入属性文件

来源:互联网 发布:贫困 知乎 编辑:程序博客网 时间:2024/05/17 00:24

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");


原创粉丝点击