If a ResourceBundle
class for the specified Locale
does not exist, getBundle
tries to find the closest match. For example, if ButtonLabel_fr_CA_UNIX
is the desired class and the default Locale
is en_US
, getBundle
will look for classes in the following order:
ButtonLabel_fr_CA_UNIX ButtonLabel_fr_CA ButtonLabel_fr ButtonLabel_en_US ButtonLabel_en ButtonLabel
Note that getBundle
looks for classes based on the default Locale
before it selects the base class (ButtonLabel)
. If getBundle
fails to find a match in the preceding list of classes, it throws a MissingResourceException
. To avoid throwing this exception, you should always provide a base class with no suffixes.
http://docs.oracle.com/javase/tutorial/i18n/resbundle/concept.html
本文深入探讨了Java中资源包获取的过程,包括如何在指定的本地化环境中查找资源类,以及默认本地化设置下的匹配顺序。重点阐述了getBundle方法在资源查找中的作用和局限性,特别强调了避免抛出缺失资源异常的方法。
426

被折叠的 条评论
为什么被折叠?



