Java Load Properties 文件,定义message信息

初始化Properties对象,load properties文件:

private
static final Properties MESSAGERESOURCES = new Properties(); static { try { MESSAGERESOURCES.load(ClassLoader.getSystemResourceAsStream("/messages.properties")); MessageFormat.format("", ""); } catch (IOException e) { mylogger.error("Error >>>> : Could not load error message resource file 'message.properties'", e); } }

message.properties 文件内容:

ERROR_MESSAGE = test product number is {0}, the env {1} can not do this.

格式化message信息:

String para[] = {"1001", "dev_1"};
String message = MessageFormat.format(MESSAGERESOURCES.getProperty(“ERROR_MESSAGE”, para);

得到的Message信息为:

test product number is 1001, the env dev_1 can not do this.

posted on 2015-02-11 18:23  马铃豆  阅读(563)  评论(0编辑  收藏  举报

导航