使用Properties动态读取/添加conf文件参数的值

kit*_*kid 5 java properties

我的conf文件中有如下消息.

text.message = Richard必须去School01/06/2012/ 1days.

所有突出显示的字段都是可变的

我想读取此text.me字符串并使用Properties从我的java中插入值.

我知道如何使用Prop阅读整个字符串,但不知道如何读取如上所述的字符串.

text.message = #name# 必须在#date#/#days#中去#place#.

  1. 如何使用属性从conf中读取上述字符串并动态插入数据?

  2. 它可以是字符串中的日期或天数.我如何在这些参数之间打开和关闭?

谢谢你.

Bal*_*usC 16

您可以使用此MessageFormatAPI.

开球示例:

text.message = {0} has to go to {1} in {2,date,dd/MM/yyyy} / {3}
Run Code Online (Sandbox Code Playgroud)

String message = properties.getProperty("text.message");
String formattedMessage = MessageFormat.format(message, "Richard", "School", new Date(), "1days");
System.out.println(formattedMessage); // Richard has to go to School in 31/05/2012 / 1days
Run Code Online (Sandbox Code Playgroud)