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 + '!';
    }
  }
}

 

转载于:https://www.cnblogs.com/idel/p/4290342.html

你可能感兴趣的:(ResourceBundle的使用)