MessageFormat

资源文件的占位符使用
error_message=CI {0} not found {1}


public class ResourceBundleUtils {

	static ResourceBundle messages;
	
	static {
		if (messages == null) {
			Locale currentLocale;
			currentLocale = new Locale("en", "US");
			messages = ResourceBundle.getBundle("conf/ErrorMessagesBundle",
					currentLocale);
			
		}
	}

	public static void main(String[] args) {
		System.out.println(ResourceBundleUtils.getMessage("error_message"));
		String[] s = {"test"};
		System.out.println(ResourceBundleUtils.getMessage("error_message", s));
	}

	public static String getMessage(String key) {
		return messages.getString(key);
	}
	
	public static String getMessage(String key, String[] args) {
		String s =  messages.getString(key);
		return MessageFormat.format(s, args);
	}
}

你可能感兴趣的:(MessageFormat)