java.lang.Object
java.util.ResourceBundle
java.util.ListResourceBundle
- 直接已知的子类:
-
AccessibleResourceBundle
ListResourceBundle是ResourceBundle的一个抽象子类,它以方便且易于使用的列表形式管理区域设置的资源。有关资源包的更多信息,请参阅ResourceBundle。
子类必须重写getContents并提供一个数组,数组中的每个项目都是一对对象。每对中的第一个元素是键,必须是一个String,第二个元素是与该键关联的值。
以下示例显示了一个资源包系列的两个成员,基本名称为"MyResources"。"MyResources"是该包系列的默认成员,"MyResources_fr"是法语成员。这些成员基于ListResourceBundle(相关的示例显示了如何向此系列添加基于属性文件的包)。此示例中的键的形式为"s1"等。实际键完全取决于您的选择,只要它们与您在程序中用于从包中检索对象的键相同即可。键区分大小写。
public class MyResources extends ListResourceBundle {
protected Object[][] getContents() {
return new Object[][] {
// 本地化此处
{"s1", "磁盘\"{1}\"包含{0}。"}, // MessageFormat模式
{"s2", "1"}, // {0}在模式中的位置
{"s3", "我的磁盘"}, // 示例磁盘名称
{"s4", "没有文件"}, // 第一个ChoiceFormat选择
{"s5", "一个文件"}, // 第二个ChoiceFormat选择
{"s6", "{0,number}个文件"}, // 第三个ChoiceFormat选择
{"s7", "96年3月3日"}, // 示例日期
{"s8", new Dimension(1,5)} // 真实对象,而非仅字符串
// 本地化材料结束
};
}
}
public class MyResources_fr extends ListResourceBundle {
protected Object[][] getContents() {
return new Object[][] {
// 本地化此处
{"s1", "Le disque \"{1}\" {0}."}, // MessageFormat模式
{"s2", "1"}, // {0}在模式中的位置
{"s3", "Mon disque"}, // 示例磁盘名称
{"s4", "ne contient pas de fichiers"}, // 第一个ChoiceFormat选择
{"s5", "contient un fichier"}, // 第二个ChoiceFormat选择
{"s6", "contient {0,number} fichiers"}, // 第三个ChoiceFormat选择
{"s7", "1996年3月3日"}, // 示例日期
{"s8", new Dimension(1,3)} // 真实对象,而非仅字符串
// 本地化材料结束
};
}
}
ListResourceBundle子类的实现必须在同时被多个线程使用时是线程安全的。此类中方法的默认实现是线程安全的。
- 自 JDK 版本:
- 1.1
- 参见:
-
Nested Class Summary
Nested classes/interfaces declared in class java.util.ResourceBundle
ResourceBundle.Control -
Field Summary
Fields declared in class java.util.ResourceBundle
parent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Object[][]返回一个数组,其中每个项目是Object数组中的一对对象。getKeys()返回包含在此ResourceBundle及其父包中的键的Enumeration。final ObjecthandleGetObject(String key) 从此资源包中获取给定键的对象。返回仅包含在此ResourceBundle中的键的Set。Methods declared in class java.util.ResourceBundle
clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, keySet, setParent
-
Constructor Details
-
ListResourceBundle
public ListResourceBundle()唯一构造函数。(通常由子类构造函数隐式调用。)
-
-
Method Details
-
handleGetObject
从类中复制的描述:ResourceBundle从此资源包中获取给定键的对象。如果此资源包不包含给定键的对象,则返回null。- 指定者:
-
handleGetObject在类ResourceBundle - 参数:
-
key- 所需对象的键 - 返回:
- 给定键的对象,或null
-
getKeys
返回包含在此ResourceBundle及其父包中的键的Enumeration。- 指定者:
-
getKeys在类ResourceBundle - 返回:
-
包含在此
ResourceBundle及其父包中的键的Enumeration。 - 参见:
-
handleKeySet
返回仅包含在此ResourceBundle中的键的Set。- 覆盖:
-
handleKeySet在类ResourceBundle - 返回:
-
仅包含在此
ResourceBundle中的键的Set - 自 JDK 版本:
- 1.6
- 参见:
-
getContents
返回一个数组,其中每个项目是Object数组中的一对对象。每对中的第一个元素是键,必须是一个String,第二个元素是与该键关联的值。有关详细信息,请参阅类描述。- 返回:
-
一个
Object数组的数组,表示键值对。
-