配置资源文件为hello.properties
package util; import java.util.ResourceBundle; public class Messages { private static final String BUNDLE_NAME = "hello"; private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(Messages.BUNDLE_NAME); public Messages() { } public static String getString(final String key) { return Messages.RESOURCE_BUNDLE.getString(key); } }
获取方式:
String cnStr = Messages.getString("CONST_STRING_TRAILS");