properties文件的读取

一、基本方式的读取:对象

创建一个properties文件有一个键值对:aa=123get

Properties pro = new Properties();
pro.load(new FileInputStream("properties/conf.properties"));
String value = pro.getProperty("aa");
System.out.println(value);配置

能够获取到properties的值;方法

二、便捷方式的获取:不用建立properties对象,能够省略上一级目录和后缀名;配置文件

ResourceBundle rb= ResourceBundle.getBundle("conf");
String value = rb.getString("aa");
System.out.println(value);
文件

一样能够获得上面第一种方法的结果;co

 

注意:配置文件应该放在resource folder的文件夹之下new

相关文章
相关标签/搜索