sriram sudhakar
sriram sudhakar

Reputation: 67

How to traverse a property folder and get the path of each property file

I have a folder called Config/DEVLOCAL/mail.properties and config/client/local//DEVLOCAL/RDOClient/client.properties. In my code I need to overwrite the properties file with my new values.

I did it by giving the exact path of the folder but my task it to get the properties file path which I have defined in the environment variable and pass it accordingly. I should not hardcode the properties file path.

PropertyFolderConfiguration propconfig = new PropertyFolderConfiguration();
PropertiesConfiguration rdoconfig =
    new PropertiesConfiguration("E:/Sriram Workspace/telmed_wrkspc/Config/DEVLOCAL/RDOClient/client.properties");    
PropertiesConfiguration mailconfig = 
    new PropertiesConfiguration("E:/Sriram Workspace/telmed_wrkspc/Config/DEVLOCAL/mail.properties");

Upvotes: 0

Views: 290

Answers (1)

radoh
radoh

Reputation: 4819

System.getProperty("user.dir")

might help you, so your code will look like

PropertiesConfiguration rdoconfig = 
  new PropertiesConfiguration(System.getProperty("user.dir") + "/Config/DEVLOCAL/RDOClient/client.properties");

(I assume E:/Sriram Workspace/telmed_wrkspc is your working directory)

Also, you might want to use File.separator instead of slashes

Upvotes: 1

Related Questions