小编udy*_*udy的帖子

在Java中读取属性文件时出现NullPointerException

我使用以下代码来读取属性文件:

Properties pro = new Properties();
InputStream is = Thread.currentThread().getContextClassLoader().
    getResourceAsStream("resources.properties");

pro.load(is);
Run Code Online (Sandbox Code Playgroud)

当我执行代码时,我收到以下错误:

Exception in thread "main" java.lang.NullPointerException
  at java.util.Properties$LineReader.readLine(Properties.java:418)
  at java.util.Properties.load0(Properties.java:337)
  at java.util.Properties.load(Properties.java:325)
  at com.ibm.rqm.integration.RQMUrlUtility.RQMRestClient.getResource(RQMRestClient.java:66)
  at com.ibm.rqm.integration.RQMUrlUtility.RQMRestClient.main(RQMRestClient.java:50)
Run Code Online (Sandbox Code Playgroud)

为什么我得到了NullPointerException?我应该在哪里保存resources.properties文件?

java inputstream nullpointerexception

18
推荐指数
2
解决办法
6万
查看次数

标签 统计

inputstream ×1

java ×1

nullpointerexception ×1