您是否尝试过使用属性?
创建配置:
属性prop = new Properties(); OutputStream输出= null;
try {
SaveSucessful = true;
output = new FileOutputStream("config.jar");
// set the properties value
prop.setProperty("PVIDNO", "PALMUS-00001");
// save properties to project root folder
prop.store(output, null);
} catch (IOException io) {
io.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
读取配置:
Properties prop = new Properties();
InputStream input = null;
try {
LoadSucessful = true;
input = new FileInputStream("config.jar");
// load a properties file
prop.load(input);
// get the property value and print it out
PlayerName = prop.getProperty("PVIDNO");
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这应该很好地工作。
哪里级'Ini'从何而来?这不是Java标准库中的类。通常你会使用类“Properties”来加载这种格式的文件。 – Jesper
@Jesper忘了提及我使用ini4j。 –
看看这个[点击我](http://stackoverflow.com/a/190633/1577167)希望这可以帮助。 – BottleMan