我有一个项目,我要将其转换为可运行的 jar 文件。我使用ini4j
.
当我简单地设置目录时getConf = new Ini(new FileReader(path));
它可以工作,但是当我使用它时它不会工作getResourceAsStream()
public class IniReader {
// When I set it like that, it works..
private static String path = "../conf.ini";
public static String readIni(String val, String getOb, String fetchOb) {
Ini getConf = null;
try {
// When I set it like that, it works..
getConf = new Ini(new FileReader(path));
// I want to use this version but I am getting null error.
//getConf = new Ini(new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.ini"))));
} catch (InvalidFileFormatException e) {
System.err.print("Error InvalidFileFormat : " + e.getMessage() + "\n");
e.printStackTrace();
} catch (FileNotFoundException e) {
System.err.print("Error FileNotFoundException : " + e.getMessage() + "\n");
e.printStackTrace();
} catch (IOException e) {
System.err.print("Error IOException : " + e.getMessage() + "\n");
e.printStackTrace();
}
return val = getConf.get(getOb).fetch(fetchOb);
}
当我尝试阅读我的 iniFile 时,我收到以下错误;
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:113)
at org.ini4j.Ini.load(Ini.java:104)
at org.ini4j.Ini.<init>(Ini.java:56)
at com.test.ttf.IniReader.readIni(IniReader.java:28)
at com.test.ttf.SlashSCR.InitProg(SlashSCR.java:116)
at com.test.ttf.InitProg.main(InitProg.java:18)
这是我要读取 .ini 文件的地方
编辑
我还尝试了以下方法;
Ini getConf= new Ini();
getConf.load(Thread.currentThread().getContextClassLoader().getClass().getResourceAsStream("../conf.ini"));