I was trying to use java's native Properties class to edit my ".properties" file and save them, but then I was put off by the fact that in order to do that I had to "store" the properties file by re-writing it back to disk, which simply erased all other properties (say if i had three properties and i edited one of them, the store method erases the other two). Someone directed me to the Apache Commons, and at first glance I was impressed because it seemed all i had to do was call the "save()" method. However, using Apache commons has been nothing short of frustrating, to say the least. Perhaps one of you out there can help me out.
First of, when loading a file it seems I cannot do this:
When I try the code above all I get is an error that says "The File has not been set!". Apparently, if I am to use the "load()" method, I am to do this:
Which makes me wonder: why on earth does the load() method allow for the inclusion of a properties file's path it doesn't work???
The only other way to load a properties file is this:
Honestly, I do not want to have to instantiate a properties configuration object everytime I want to load a properties file. It just seems too messy ... and a bit daft.
Also, say, within my properties file I have a key called "flag" and I want to change it's value, I do this:
"j" is rightly printed on the console. However when I open the properties file, "j" isn't there! Even if I closed down my netbeans, opened it again and ran just I still get "j", but "j" isn't anywhere in the properties file.
So where is it? Where does "j" get stored??? Is Apache Commons really that good, or am I wasting my time with it?
Joined: May 24, 2012
Come on, isn't there anyone who has an answer to this? I thought this was the java forum people with java problems came to for answers... Oh well