dynamically read/add value to the parameter of conf file with Properties

前端 未结 2 2079
栀梦
栀梦 2021-02-06 13:25

I have a message like below in my conf file.

text.message = Richard has to go to School in 01/06/2012 / 1days.

<
2条回答
  •  情歌与酒
    2021-02-06 13:51

    You can use the MessageFormat class, which replaces dynamic placeholders in a string with the desired values.

    For example, the following code...

    String pattern = "{0} has to go to {1} in {2,date} / {3,number,integer} days.";
    String result = MessageFormat.format(pattern, "Richard", "school", new Date(), 5);
    System.out.println(result);
    

    ...will produce the following output:

    Richard has to go to school in 31-May-2012 / 5 days.
    

    You can simply get the pattern from your Properties object, then apply the MessageFormat translation.

提交回复
热议问题