public class PropertyResourceBundle
extends ResourceBundle
| java.lang.Object | ||
| java.util.ResourceBundle | ||
| java.util.PropertyResourceBundle | ||
PropertyResourceBundle是的具体子类ResourceBundle管理资源使用一组属性文件中的静态字符串的语言环境。 有关资源包的更多信息,请参阅ResourceBundle 。
与其他类型的资源包不同,您不需要子类PropertyResourceBundle 。 而是提供包含资源数据的属性文件。 ResourceBundle.getBundle将自动查找相应的属性文件并创建引用它的PropertyResourceBundle 。 有关搜索和实例化策略的完整说明,请参见ResourceBundle.getBundle 。
以下example显示基本名称为“MyResources”的资源包系列的成员。 该文本定义了捆绑系列的德国成员“捆绑销售商MyResources_de”。 此成员基于PropertyResourceBundle ,因此文本是文件“MyResources_de.properties”的内容(相关的example显示了如何向该系列添加捆绑包,并将其作为子类ListResourceBundle )。 这个例子中的键的形式是“s1”等。实际的键完全取决于您的选择,只要它们与您在程序中用于从捆绑中检索对象的键相同即可。 密钥区分大小写。
# MessageFormat pattern
s1=Die Platte \"{1}\" enth"alt {0}.
# location of {0} in pattern
s2=1
# sample disk name
s3=Meine Platte
# first ChoiceFormat choice
s4=keine Dateien
# second ChoiceFormat choice
s5=eine Datei
# third ChoiceFormat choice
s6={0,number} Dateien
# sample date
s7=3. M"arz 1996
注意: PropertyResourceBundle可以从InputStream或者Reader中构建,它代表一个属性文件。 从InputStream构造一个PropertyResourceBundle实例需要输入流在ISO-8859-1中进行编码。 在这种情况下,不能用ISO-8859-1编码表示的字符必须用The JavaTM Language Specification的 3.3节中定义的Unicode转义表示,而采用Reader的其他构造函数不具有该限制。
Inherited fields |
|---|
java.util.ResourceBundle
|
Public constructors |
|
|---|---|
PropertyResourceBundle(InputStream stream) 从 |
|
PropertyResourceBundle(Reader reader) 从 |
|
公共方法(Public methods) |
|
|---|---|
Enumeration<String> |
getKeys() 返回一个 |
Object |
handleGetObject(String key) 从此资源包获取给定键的对象。 |
Protected methods |
|
|---|---|
Set<String> |
handleKeySet() 返回 |
继承方法(Inherited methods) |
|
|---|---|
java.util.ResourceBundle
|
|
java.lang.Object
|
|
PropertyResourceBundle (InputStream stream)
从InputStream创建一个属性资源包。 使用此构造函数读取的属性文件必须在ISO-8859-1中进行编码。
| 参数(Parameters) | |
|---|---|
stream |
InputStream: an InputStream that represents a property file to read from. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs |
NullPointerException |
if stream is null |
PropertyResourceBundle (Reader reader)
从Reader创建一个属性资源包。 与构造函数PropertyResourceBundle(InputStream)不同,对输入属性文件的编码没有限制。
| 参数(Parameters) | |
|---|---|
reader |
Reader: a Reader that represents a property file to read from. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs |
NullPointerException |
if reader is null |
Enumeration<String> getKeys ()
返回一个 Enumeration包含在此按键 ResourceBundle及其父包。
| 返回(Returns) | |
|---|---|
Enumeration<String> |
an Enumeration of the keys contained in this ResourceBundle and its parent bundles. |
也可以看看:
Object handleGetObject (String key)
从此资源包获取给定键的对象。 如果此资源包不包含给定键的对象,则返回null。
| 参数(Parameters) | |
|---|---|
key |
String: the key for the desired object |
| 返回(Returns) | |
|---|---|
Object |
the object for the given key, or null |