2013-04-07 48 views
0

我想要的值追加到這樣的重點如下:如何使用ini4j將值附加到密鑰?

[Section] 
Key=value1,value2 

我試圖Wini和第GETALL()和的putAll()函數,但它總是會替換值1與值2,而不是追加值2。我沒有找到關於這個在線的任何教程。我如何使用ini4j來做到這一點?或者另一個jni writinig和解析庫?

回答

0

我最終把它當作一個單一的鍵值對,並在「Key =」之後附加到字符串上。

0

本主題是有點老了,但我確切面臨同樣的問題,所以...

要閱讀所有:

//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和名稱):

//if myStr[] have changes 
names.putAll("myKey1", myStr); 

在最終你會擁有這樣的ini文件( 「myKey1」 始終是相同的):

[mySectionX] 
myKey1 = value1 
myKey1 = value2 
myKey1 = value3 
0

添加更多的信息, 如果你想o創建一個新的文件:

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));