在我正在研究的一个程序中,我有
String cwd;
String file_separator;
public ConfigLoader()
{
cwd = get_cwd();
file_separator = get_file_separator();
try
{
Properties c = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream(cwd +
file_separator + "data" + file_separator + "configuration.properties");
c.load(in);
}
except (Exception e) { e.printStackTrace(); }
}
public String get_file_separator()
{
File f = new File("");
return f.separator;
}
public String get_cwd()
{
File cwd = new File("");
return cwd.getAbsolutePath();
}
但是,由于某种原因,c.load(in);
会导致NullPointerException
. 例外来自in == NULL
真实。我不知道为什么,因为
System.out.println(cwd + file_separator + "data" + file_separator +
"configuration.properties");
印刷
/users/labnet/st10/jjb127/workspace/Brewer-Client/data/configuration.properties
这是我要使用的文件的位置。
想法?