ZhangBlossom 2022-02-18 23:15 采纳率: 0%
浏览 20

使用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

  • 写回答

1条回答 默认 最新

  • 王炳鑫 2022-02-19 00:20
    关注

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

    评论

报告相同问题?

问题事件

  • 创建了问题 2月18日