@Test public void test2() throws Exception { Properties pro = new Properties(); //读取配置文件的方式一: /*FileInputStream fis = new FileInputStream("src/jdbc.properties"); pro.load(fis);*/ //读取配置文件的方式二: ClassLoader classLoader = ClassLoaderTest.class.getClassLoader(); InputStream is = classLoader.getResourceAsStream("jdbc.properties"); pro.load(is); String username = pro.getProperty("username"); String password = pro.getProperty("password"); System.out.println("username:"+username+",password:"+password); }