我在获取国家货币时遇到问题,我通过这些代码在数据库中获取国家代码我必须在 java 中获取国家代码我如何为此制作代码请建议我。我正在尝试这个例子,但它不起作用。
class Utils {
public static SortedMap<Currency, Locale> currencyLocaleMap;
static {
currencyLocaleMap = new TreeMap<Currency, Locale>(
new Comparator<Currency>() {
public int compare(Currency c1, Currency c2) {
return c1.getCurrencyCode().compareTo(
c2.getCurrencyCode());
}
});
for (Locale locale : Locale.getAvailableLocales()) {
try {
Currency currency = Currency.getInstance(locale);
currencyLocaleMap.put(currency, locale);
} catch (Exception e) {
}
}
}
public static String getCurrencySymbol(String currencyCode) {
Currency currency = Currency.getInstance(currencyCode);
System.out.println(currencyCode + ":-"
+ currency.getSymbol(currencyLocaleMap.get(currency)));
return currency.getSymbol(currencyLocaleMap.get(currency));
}
}
public class GetCurrency {
public static void main(String[] args) {
Utils.getCurrencySymbol(Currency.getInstance("INR").getCurrencyCode());
Utils.getCurrencySymbol(Currency.getInstance(Locale.JAPAN)
.getCurrencyCode());
Utils.getCurrencySymbol(Currency.getInstance(Locale.UK)
.getCurrencyCode());
Utils.getCurrencySymbol("INR");
}
}