【发布时间】:2021-05-20 17:40:51
【问题描述】:
我正在尝试在我的程序中进行国际化,我发现了这个简单的示例如何使用它:
package tests;
import java.util.*;
public class I18NSample {
static public void main(String[] args) {
String language;
String country;
if (args.length != 2) {
language = new String("en");
country = new String("US");
} else {
language = new String(args[0]);
country = new String(args[1]);
}
Locale currentLocale;
ResourceBundle messages;
currentLocale = new Locale(language, country);
messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
System.out.println(messages.getString("greetings"));
System.out.println(messages.getString("inquiry"));
System.out.println(messages.getString("farewell"));
}
}
但每次我编译代码时都会出现这个异常:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name messages, locale en_US
我的文件被命名为 MessagesBundle_en_US.properties 和 MessagesBundle_es_ES.properties 并与 I18NSample 类放在同一个包中,所以我认为它应该可以工作。
【问题讨论】: