我在春天有一个属性文件,如下所示。
label.company.name = ABC Company
label.company.address = 123, west street
label.company.message = Welcome to ABC Company
我面临的问题是这个公司名称可能会有所不同,并且文件中公司名称引用的地方很多。因此,如果我更改公司名称,则属性文件中引用公司名称的所有位置也应该更改。不应使用字符串搜索和替换(根据给我的说明)。我怎样才能继续上述任务。
在 jsp 文件中调用这些属性,如下所示
<spring:message code="label.company.name"></spring:message>
请帮助我。谢谢
您可以在 Java 类中使用以下代码更改现有属性,
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();
}
}
}
或者,如果您想在jsp
中执行此操作,请将上述代码放在<% %>
块中。