Ini4J Changing my Entire INI file Instead of 1 Key Setting

1.7k views Asked by At

I am writing a Java application that I just need it to make a change to one key setting within an ini file. I am using ini4j to do this, but have come across some issue when loading the file.

The file looks like what I have here below:

[SECTION 1]
#Some Commented text
Key1=value 1 for key 1
+value 2 for key 1
+value 3 for key 1

Key2=value for key 2<BR>
Key3=value for key 3<BR>

Whats happening is that when my app goes to change one setting (key 3 for example), it changes the entire file and I get what I have here below:

[SECTION 1]
#Some Commented text
Key1=value 1 for key 1
+value 2 for key 1=
+value 3 for key 1=

Key2=value for key 2
Key3=new value 1 for key 3
+new value 2 for key 3

Notice that ini4j recognizes my multivalued keys on new lines as key settings and places an = sign at the end of it, as well as changes all of the commenting from ; to # (which shouldn't cause an issue but would prefer that nothing else but the key I specify be changed).

I was able to isolate the problem happening right when I load the ini file using the code snippet I have below:

String iniFileLoc = "my path\\iniFile.ini";

    String valueLine = "value 1 for key 3\n" + "+value 2 for key 3\n";
    Wini ini = new Wini();
    File iniFile = new File(iniFileLoc);
    ini.load(iniFile);


        ini.add("SECTION1", "Key3", valueLine);

        ini.store(iniFile);

Is there any way to keep ini4j from changing anything else but the specific key i spcify? If not, how can I keep ini4j from recognizing uncommented lines as necessarily being key settings. The ini file I am working with is required to be in this format so i'm not able to specify another method of having multivalued keys other than using the + signs.

Any help would be greatly appreciated.

Thanks

0

There are 0 answers