本例主要以java实现和jdbc在连接 1.在properties文件中在数据(取名为test01.properties,该文件在src下建立) dbUrl=jdbc:mysql://localhost:3306/db_test username=root password=root dbName=com.mysql.jdbc.Driver 2.读取 properties配置文件在工具类(取名
碰到一个properties的资源文件,读取报空指针,什么原因?
我使用下面2中方式读取,都是空指针。
Properties pro
= new Properties();
pro.load(Demo.class.getResourceAsStream("/project/db.properties"));
pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("project/db.properties"));
Exception:
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at project.HashMap.Demo.main(Demo.java:23),
空指针异常,看看是不是23行有变量初始化为空或者没有初始化!,