您的位置:首页 > 运维架构

读取配置文件properties的方法

2017-06-22 17:36 495 查看
方法一:通过Class的getResourceAsStream方法和Properties的load方法读取*.properties文件的内容;

@Test
//读取配置文件
public void readProperties() throws IOException {
//通过Class的getResourceAsStream方法获取根目录下hibernate.properties文件的输入流
InputStream inputStream = Reflect1.class.getResourceAsStream("/hibernate.properties");
Properties properties = new Properties();
//将properties文件中的属性读入到对象properties中
properties.load(inputStream);
//get方法获取对应的值
String username = (String) properties.get("hibernate.connection.username");
System.out.println(username);
inputStream.close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: