第一种,正常输入流:
@Test
public void test1(){
Properties pro = new Properties();
//这种方法读取,默认在工程目录下!!
FileInputStream fis = new FileInputStream("jdbc.properties");
pro.load(fis)
}
第二种 反射 类加载器方式读取:
@Test
public void test2() throws IOException {
ClassLoader classLoader = ClassLoaderTest.class.getClassLoader();
Properties properties = new Properties();
//以流的方式来获取资源(默认在src下)
InputStream ras = classLoader.getResourceAsStream("jdbc.properties");
properties.load(ras);
}
两种方式取得的资源路径不同, 第一种路径可以写成"src\jdbc.properties"