使用getClassLoader.getResourceAsStream读取property文件返回null

public void connection5() throws Exception {
    InputStream inputStream = Connection.class.getClassLoader().getResourceAsStream("D:\\StudentInfo\\src\\JDBCTest\\jdbc1.properties");
    Properties pro  = new Properties();
    pro.load(inputStream);
    this.user=pro.getProperty("user");
    this.user=pro.getProperty("password");
    this.user=pro.getProperty("driver");
    this.user=pro.getProperty("url");
    Class.forName(driver);//加载驱动
    DriverManager.getConnection(url,user,password);
}

我直接用的是property文件的绝对路径但是最后返回的还是null不知道是为什么

img

getClassLoader.getResourceAsStream这个方法好像只可以加载classpath路径下面的资源,你试试直接写getClassLoader.getResourceAsStream(“jdbc1.properties“)