Properties文件读取
时间:2021-03-11 13:15:09
收藏:0
阅读:0
Service层和dao层写接口层时,properties文件的信息读取: 读取配置文件的信息
之前
Propertry prop = New Propertry();
Prop.load(new FileReader());
// 属性 其值在静态代码块获取,这个类在项目启动被加载的时候,读取一次配置文件;
private static Properties prop = null;
// 静态代码块
static {
prop = new Properties();
// 加载
try {
prop.load(new FileReader("bean.properties"));
} catch (IOException e) {
throw new RuntimeException("配置文件加载失败!");
}
}
=============
ResourceBundle rb = ResourceBundle.getBundle(“配置文件”) //不带后缀名
String className = rb.getString(key);
评论(0)