I need to read a config file I get this error while running the following code:
java.util.Properties$LineReader.readLine
The file config.cfg is present and has r/w permissions.
import java.util.*;
import java.util.Properties;
public class Config
{
Properties configFile;
public Config()
{
configFile = new java.util.Properties();
try {
configFile.load(this.getClass().getClassLoader().
getResourceAsStream("config.cfg"));
}catch(Exception eta){
eta.printStackTrace();
}
}
public String getProperty(String key)
{
String value = this.configFile.getProperty(key);
return value;
}
}
[java] java.lang.NullPointerException
[java] at java.util.Properties$LineReader.readLine(Properties.java:418)
[java] at java.util.Properties.load0(Properties.java:337)
[java] at java.util.Properties.load(Properties.java:325)
[java] at Config.<init>(Unknown Source)
[java] at ClosureBuilder.<clinit>(Unknown Source)
src
-> config.java
-> config.cfg
You have to put your config.cfg
in the same folder where your .class
file lies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With