java.util.Properties$LineReader.readLine [英] java.util.Properties$LineReader.readLine
本文介绍了java.util.Properties$LineReader.readLine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要读取一个配置文件运行以下代码时出现此错误:
I need to read a config file I get this error while running the following code:
java.util.Properties$LineReader.readLine
文件 config.cfg 存在并且具有 r/w 权限.
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)
编辑 - 目录结构
源代码
-> config.java
-> config.java
-> config.cfg
-> config.cfg
推荐答案
您必须将 config.cfg
放在 .class
文件所在的同一文件夹中.
You have to put your config.cfg
in the same folder where your .class
file lies.
这篇关于java.util.Properties$LineReader.readLine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文