ResourceBundle的使用

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class ConfKit{
  private static final String BUNDLE_NAME = "config";//config.properties
  private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

  private ConfKit() {}

  public static String getString(String key) {
    try {
      return RESOURCE_BUNDLE.getString(key);
    }catch (MissingResourceException e) {
      return '!' + key + '!';
    }
  }

  public static String getString(String key, String[] paras) {
    try {
      String message = RESOURCE_BUNDLE.getString(key);
      return MessageFormat.format(message, paras);
    }catch (MissingResourceException e) {
      return '!' + key + '!';
    }
  }
}

 

posted on 2015-02-13 15:18  汤能养身  阅读(431)  评论(0)    收藏  举报

导航