获取空指针异常在FILE类中

时间:2014-10-08 07:31:44

标签: java file nullpointerexception

File file = new File(getClass().getResource(filePath + "/createFile.xml").toURI());

我在上面的行中收到java.lang.NullPointerException错误。这里filePath是字符串变量,我在其中设置了我想要读取文件的目录路径。

1 个答案:

答案 0 :(得分:1)

找不到资源时,

Class.getResource()将返回null。在使用它之前,你总是应该测试它。

相关问题