I am using the classLoader method to load a property file. Using this, I am able to retrieve the values of properties but now I want to update the values of some properties and i am not able to do it. Please help. Here, is the code:
here, in propValue i get the right value from file. I am updating this like this:
Using this the value doesn't get update but when i provide the complete path for PublishDate.properties then it works. But, I don't want to give the complete path as the path is dynamic. Does someone knows how to do this using some relative path. Please advise me on this.
In current scenario I suspect when you try to update the property it creates a new file instead of updating the current one, whose location is different from the one which is actually read.
I mean the class loader will look for the file under the same directory where the .Class file is located where as when you go and update the property using new FileOutputStream("PublishDate.properties") the absolute path for this is different, that is the reason when you give complete path it works fine.
To know where the new file is getting saved just put this code in your file.
File f = new File("PublishDate.properties");
it will print the absolute path for the file, you can check if it exists under the directory and contains the updated value.
Eg. if your .class file is under D:/workspace/example/src then for class loader the publishDate.properties must be present under the same directory where as when you update the absolute path will be D:/workspace/example
Joined: Aug 26, 2011
Thanks a lot for your help. But, when I use new FileInputStream("PublishDate.properties"), it throws FileNotFound Exception and when I pass complete path in this, then it works fine.
Joined: Jul 30, 2010
That means the file you are reading does not exist.....create the file under the directory it is searching in.... and it should work.
What the absolute path of the property file and the src file you are using?
Joined: Aug 26, 2011
I am really sorry for posting it multiple times. I did it by mistake. Also, my problem has been solved. Instead of using this approach, I used common configuration's PropertiesConfiguration for updating property file and it is working perfectly fine. Thanks for all your help.