aspose file tools*
The moose likes Java in General and the fly likes Editing Properties file with Apache Commons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Editing Properties file with Apache Commons" Watch "Editing Properties file with Apache Commons" New topic
Author

Editing Properties file with Apache Commons

Akin Agbaje
Greenhorn

Joined: May 24, 2012
Posts: 2
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?
Akin Agbaje
Greenhorn

Joined: May 24, 2012
Posts: 2
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
Read this. People are helping unpaid, and you will simply have to wait until somebody who knows the answer comes by.
Gaurav Lala
Greenhorn

Joined: Mar 29, 2012
Posts: 12

The same problem for me as well..... Even clean build and restarting Eclipse doesn't work.....

Strange that no body has ever provided a solution to this....
Gaurav Lala
Greenhorn

Joined: Mar 29, 2012
Posts: 12

I got it working...the .properties file has been saved in 2 locations....i did not know that.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Editing Properties file with Apache Commons