方式一:
/*
Properties:用来读取配置文件
*/
@Test
public void test2() throws Exception {
Properties pros = new Properties();
//读取配置文件方式一:
FileInputStream fis = new FileInputStream("src/com/atguigu/java/jdbc.properties");
//加载配置文件
pros.load(fis);
String user = pros.getProperty("user");
String password = pros.getProperty("password");
System.out.println(user +"," + password);
}
方式二:
/*
Properties:用来读取配置文件
*/
@Test
public void test2() throws Exception {
Properties pros = new Properties();
//读取配置文件方式二:使用ClassLoader
ClassLoader classLoader = ClassLoaderTest.class.getClassLoader();
InputStream resourceAsStream = classLoader.getResourceAsStream("com/atguigu/java/jdbc.properties");
pros.load(resourceAsStream);
String user = pros.getProperty("user");
String password = pros.getProperty("password");
System.out.println(user +"," + password);
}