遇到的问题:
在学习JavaWeb的数据库连接池时,使用InputStream读取properties的文件时出现空指针异常。
InputStream in = new Example02().getClass().getClassLoader().
getResourceAsStream("dbcpconfig.properties");`
解决方法:
在项目的project structure中,将src文件夹设置为Resources,应用并关闭。
将properties文件移动至resources文件夹中,
同时要将代码中的路径修改,
InputStream in = new Example02().getClass().getClassLoader().
getResourceAsStream("main/resources/dbcpconfig.properties");
异常消失。