获得properties文件中某个key对应着的value
// 路径名称 + properties的名称,不要“properties”
private static final String BUNDLE_NAME = "com.xxx.cs.mm.service.messages"; private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
Format其中的值
MessageFormat.format(RESOURCE_BUNDLE.getString("SomeKey"), new Object[] { "1", "2" }));