我已经尝试了属性文件路径的变体,但似乎无法正确。
Here's the structure:
src/
├── properties.properties
└── teln
├── ConnectMUD.java
├── IOUtil.java
└── PropertiesReader.java
和错误:
run:
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at teln.PropertiesReader.getProps(PropertiesReader.java:16)
at teln.ConnectMUD.main(ConnectMUD.java:18)
和有问题的班级:
package teln;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PropertiesReader {
private static final Logger LOG = Logger.getLogger(PropertiesReader.class.getName());
private static Properties props = new Properties();
public static Properties getProps() {
try {
props.load(PropertiesReader.class.getResourceAsStream("/teln/teln.properties"));
} catch (IOException ex) {
Logger.getLogger(PropertiesReader.class.getName()).log(Level.SEVERE, null, ex);
}
LOG.fine(props.toString());
return props;
}
}
项目是Teln
,包是teln
(也许不是好的选择)。