File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Editing Properties file with Apache Commons

 
Akin Agbaje
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this. People are helping unpaid, and you will simply have to wait until somebody who knows the answer comes by.
 
Gaurav Lala
Greenhorn
Posts: 12
Chrome
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
Chrome
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic