标签:
初始化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