import java.text.MessageFormat; import java.util.ResourceBundle; /** * A tool used to get the parameters from resource files. * * @author lixq * @version 1.0 */ public class MessageBundle { /** * Initializes ResourceBundle with resource file. */ private static ResourceBundle bundle = ResourceBundle .getBundle("MUConfig"); private MessageBundle() { } /** * Get a message from the bundle. * * @param key The message key * @return The message */ public static String get(final String key) { String message = null; try { // Get the message message = bundle.getString(key); } catch (RuntimeException e) { // If messasge was not found, return the key message = key; } return message; } /** * Get the message from MessageBundle * and stuff an argument into the message. * * @param key The message key * @param argument The arguments for the message * @return The message */ public static String get(final String key, final String argument) { String message = MessageBundle.get(key); return MessageFormat.format(message, new Object[] {argument}); } /** * Get the message from MessageBundle * and stuff multiple arguments into the message. * * @param key The message key * @param arguments The arguments for the message * @return The message */ public static String get(final String key, final Object[] arguments) { String message = MessageBundle.get(key); return MessageFormat.format(message, arguments); } }
java资源类_java资源文件操作类
最新推荐文章于 2024-05-11 01:53:45 发布