Jince Martin Jince Martin - 10 months ago 37
Java Question

How to get all properties files in a package and update the key values using java?

I tried a lot, but was unable to find a solution.


This is my project structure.

I have a updatePropertiesFile class, to update a key for all the properties file. I have around 200 properties file.

So what I need is that, I need to write a method to update a particular key in all these properties file. Manual change is not that practically. I need to write an application which does this funtionality.

I tried using resoucebundle mechanism. But using resource bundle, we can get only one property file. I tried

I need an iteration through these properties file and updation for the key.

Answer Source

Every Java IDE out there has a replace-in-path function. Sublime Text, VS Code and Atom almost certainly have that as well. IntelliJ's particularly good. No reason to even write Java code to do this. Otherwise, it's as simple as:

File[] files = new File("src/main/resources").listFiles();
for (File file in files) {
    if (file.getName().endsWith("properties")) {
        //Load and change...