Properties读取
Properties prop = new Properties();// 属性集合对象
FileInputStream fis = new FileInputStream(path);// 属性文件输入流
prop.load(fis);// 将属性文件流装载到Properties对象中
fis.close();// 关闭流
value = prop.getProperty(key);
Properties方式获取的配置文件均没有被缓存。每次都要重新加载配置文件
ResourceBundle
// ResourceBundle rb = ResourceBundle.getBundle("配置文件相对工程根目录的相对路径(不含扩展名)");
ResourceBundle rb = ResourceBundle.getBundle("config");
try{
String name = rb.getString("name");
}
注意:上述方式会缓存配置文件信息,后续读取时均是读取缓存中的内容,若在此期间修改了配置内容是无法实时同步的