0

I have a property file in spring as shown below.

label.company.name = ABC Company
label.company.address = 123, west street
label.company.message = Welcome to ABC Company

The problem I am facing is that this company name can vary, and there are lot of places that the company name refers in the file. So if I change the company name, all the places referring to the company name in the property file should also change. string search and replace should not be used (as per instructions given to me). How can i proceed with the above task.

The properties are called in the jsp files as follows

<spring:message code="label.company.name"></spring:message>

Please help me. Thank you

Lahiru Tjay
  • 159
  • 2
  • 4
  • 14

1 Answers1

0

You can change the existing property using the below code in your Java class,

Properties prop = new Properties();
OutputStream output = null;
try {
    output = new FileOutputStream("filePath/fileName.properties");
    prop.setProperty("label.company.name", "new company name");
    prop.store(output, null);
} catch (IOException io) {
    // If file not found or does not exists
    io.printStackTrace();
} finally {
    if (output != null) {
        try {
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Or if you want to do this in jsp then put the above code in <% %> block.

VPK
  • 3,010
  • 1
  • 28
  • 35