方法一:通过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();
}