本文介绍了使用Properties动态读取/添加conf文件参数的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的conf文件中有如下信息。

I have a message like below in my conf file.

text.message = Richard 必须去到学校 in 01/06/2012 / 1days

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

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

All highlighted field will be variable.

我想阅读这个文本。我字符串并使用属性从我的java中插入值。

I want to read this text.me string and insert the value from my java using Properties.

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

I know how to read the whole string using Prop, but don't know how to read like above String which will be like.

text.message = #name#必须去#place#in#date#/ #days#。

text.message = #name# has to go to #place# in #date# / #days#.


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

  1. how can I read the above string from the conf using Properties and insert data dynamically?

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

It can be either date or days in the string. How I can turn on and off between those parameters?

提前致谢。

推荐答案

您可以使用这个API。

You can use the MessageFormat API for this.

开球示例:

text.message = {0} has to go to {1} in {2,date,dd/MM/yyyy} / {3}

with

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

这篇关于使用Properties动态读取/添加conf文件参数的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:15
查看更多