java - 读取属性文件时获取空指针

标签 java properties

读取属性文件时,出现 nullpointer 异常。

faceConfig.load(ReadPropertyFile.class.getClassLoader().getResourceAsStream("/resources/faces.properties"));

下面是属性文件的路径facedetections/src/main/resources/faces.properties

我尝试了不同的组合,因为我的类文件在以下路径中读取 /facedetections/src/main/java/com/facial/facedetection/utils/ReadPropertyFile.java

组合为 ../../../../../resource/faces.properties/resource/faces.properties

../../../resource/faces.properties

请建议我可以为此提供的正确路径是什么。

编辑: 我提取了 war 文件并在下面提供了它的路径。 war extraction

最佳答案

在类文件夹下而不是在资源中查找属性文件。 因为您的屏幕截图无法在类文件夹下找到资源文件夹。

所以只需使用

 ReadPropertyFile.class.getClassLoader().getResourceAsStream("faces.properties")

关于java - 读取属性文件时获取空指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18523996/

相关文章:

java - Struts 2 中的 session

ios - 以编程方式创建 View 强属性

javamail : how to have two set of (System. getProperties())

java - Spring 和 Quartz 与 Java Config 的集成

java - 如果创建新实例,字符串是否会失去可变性

java - 我可以使用什么来代替 Java 中的 Vector?

c# - 在自己的类中动态设置属性

java - 需要有关此 Java 输出的帮助

javascript - JS 对象属性定义速记

iphone - 自动释放和属性