我正在尝试在静态初始化代码中加载 Java 中的属性文件:
public class NFWConfiguration {
private static final Properties PROPS = new Properties();
static {
try {
InputStream IS = NFWConfiguration.class.getClassLoader()
.getResourceAsStream(
"/net/nfw/Configuration/NFWConfiguration.properties");
PROPS.load(IS);
} catch (IOException ex) {
Logger.getLogger(NFWConfiguration.class.getName())
.log(Level.SEVERE, null, ex);
}
}
// ...
}
然而,我收到以下错误消息:
Caused by: 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 net.nfw.Configuration.NFWConfiguration.<clinit>(NFWConfiguration.java:28)
确实IS
如此null
,但它没有理由如此null
。我已经仔细检查了.jar
,并且属性文件在正确的目录中。
我究竟做错了什么?