Java 如何使用ini4j将值附加到键?

Java 如何使用ini4j将值附加到键?,java,ini,ini4j,Java,Ini,Ini4j,我想向以下键添加一个值,如下所示: [Section] Key=value1,value2 我尝试了Wini和Section getAll()和putAll()函数,但它总是用value2替换value1,而不是附加value2。我没有在网上找到任何关于这个的教程。如何使用ini4j实现这一点?还是另一个jni编写和解析库?我最终将其作为单个键值对处理,并附加到“Key=”后面的字符串中。这个主题有点老,但我面临着完全相同的问题,所以 阅读全文: //open the file Ini ini

我想向以下键添加一个值,如下所示:

[Section]
Key=value1,value2

我尝试了Wini和Section getAll()和putAll()函数,但它总是用value2替换value1,而不是附加value2。我没有在网上找到任何关于这个的教程。如何使用ini4j实现这一点?还是另一个jni编写和解析库?

我最终将其作为单个键值对处理,并附加到“Key=”后面的字符串中。

这个主题有点老,但我面临着完全相同的问题,所以

阅读全文:

//open the file
Ini ini = new Ini(new File(iniFileName));

//load all values at once
Ini.Section names = ini.get("mySectionX");
myStr[] = names.getAll("myKey1", String[].class);
要放置所有(具有相同的ini和名称):

最后,您将得到如下ini文件(“myKey1”始终相同):

添加更多信息, 如果要创建新文件,请执行以下操作:

Ini ini = new Ini();
ini.setComment(" Main comment ");  //comment about the file

//add a section comment, a section and a value
ini.putComment("mySectionX", " Comment about the section");
ini.put("mySectionX", "myKey1", "value1");

//adding many parameters at one in a section
String[] keyList = {value1, value2, value3};
ini.add("mySectionY");
Ini.Section names = ini.get("mySectionY");
names.putAll("myKey1", keyList);           //put all new elements at once
...
ini.store(new File(iniFileName));
[mySectionX]
myKey1 = value1
myKey1 = value2
myKey1 = value3
Ini ini = new Ini();
ini.setComment(" Main comment ");  //comment about the file

//add a section comment, a section and a value
ini.putComment("mySectionX", " Comment about the section");
ini.put("mySectionX", "myKey1", "value1");

//adding many parameters at one in a section
String[] keyList = {value1, value2, value3};
ini.add("mySectionY");
Ini.Section names = ini.get("mySectionY");
names.putAll("myKey1", keyList);           //put all new elements at once
...
ini.store(new File(iniFileName));