-3

So I have a .properties file in java. One of the properties hold the value for a certain path which happened to change.

What I did is edit the .properties file to change the value to the new path. However it seems that I am always reading the old value.

What could be the reason for that ?

EDIT This is how I read the properties file

propertiesFilePath = "configs/index.properties"; Properties properties = new Properties(); InputStream input = new FileInputStream(propertiesFilePath); properties.load(input);

Abdelrahman Shoman
  • 2,882
  • 7
  • 36
  • 61
  • When running you application are you explicitly providing this properties file in classpath? – ProgrammerBoy Apr 17 '17 at 06:33
  • If you're doing Java web stuff, did you make sure that the new properties file got deployed? – Tim Biegeleisen Apr 17 '17 at 06:33
  • How are you reading properties file ? – jmj Apr 17 '17 at 06:34
  • 1
    The file you have edited is not the one that is used to read the properties from. – Henry Apr 17 '17 at 06:34
  • @SanketD .. I edit my question to explain how I read the properties file – Abdelrahman Shoman Apr 17 '17 at 06:38
  • @TimBiegeleisen no, not web stuff .. it is a local java code – Abdelrahman Shoman Apr 17 '17 at 06:38
  • @Henry I provide the path to the properties file .. as I am just running a local java code (not a jar file) I can't see how can I provide an invalid properties path – Abdelrahman Shoman Apr 17 '17 at 06:40
  • 2
    We can go on and guess more reasons why this happens ("you forgot to save the edited file" and "the property value is not used because it is later overwritten with a hard coded value" are two of them) or you find out more with a debugger. – Henry Apr 17 '17 at 06:43
  • @Henry well thanks for the suggestion, it actually helped. Since I did not wrote this code from the scratch I was missing some details in the reading process .. it was reading from a different property file .. thanks – Abdelrahman Shoman Apr 17 '17 at 06:46
  • [`properties.load(input);`](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Properties.java#Properties.load%28java.io.InputStream%29) actually reads content and puts into memory. change made physically on disk won't reflect. you will have to re-read it to get the change – jmj Apr 17 '17 at 06:46

1 Answers1

1

There could be two reason for this.

  1. You have multiple index.properties present and you are updating the properties in wrong file. Also ensure you don't have multiple entries for same property.

  2. After updating your .properties file, you are not restarting your application. You should restart to have it read the updated properties or you have to explicitly have functionality in your code to load it when there is change in his file(this is also do able).

ProgrammerBoy
  • 876
  • 6
  • 19