码迷,mamicode.com
首页 > 编程语言 > 详细

Java Load Properties 文件,定义message信息

时间:2015-02-11 20:27:57      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

初始化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.

Java Load Properties 文件,定义message信息

标签:

原文地址:http://www.cnblogs.com/xbingxin/p/4286781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!