public class PropertyResourceBundle extends ResourceBundle
PropertyResourceBundle是的具体子类ResourceBundle管理资源使用一组属性文件中的静态字符串的语言环境。
有关资源束的更多信息,请参阅ResourceBundle 。
不同于其他类型的资源束,您不需要PropertyResourceBundle子类。 而是提供包含资源数据的属性文件。 ResourceBundle.getBundle会自动查找相应的属性文件,并创建一个引用它的PropertyResourceBundle 。 有关搜索和实例化策略的完整说明,请参阅ResourceBundle.getBundle 。
下面example显示了资源包系列中具有基本名称“为MyResources”的成员。 该文本定义了捆绑包系列的德语成员“MyResources_de”捆绑包。 该成员基于PropertyResourceBundle ,因此文本是“MyResources_de.properties”文件的内容(相关的example显示如何添加捆绑包到这个家庭,实现为ListResourceBundle的ListResourceBundle )。 此示例中的键的格式为“s1”等。实际的键完全取决于您的选择,只要它们与您在程序中使用的键相同即可从包中检索对象。 密钥区分大小写。
# MessageFormat pattern
s1=Die Platte \"{1}\" enthält {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ärz 1996
PropertyResourceBundle子类的实现必须是线程安全的,如果它被多个线程同时使用。 该类中非抽象方法的默认实现是线程安全的。
注意: PropertyResourceBundle可以由一个InputStream或一个Reader来构造,它表示一个属性文件。 从InputStream构造PropertyResourceBundle实例要求输入流在ISO-8859-1中进行编码。 在这种情况下,不能在ISO-8859-1编码表示的字符必须由Unicode转义如在The Java™ Language Specification第3.3节中定义,而其他的构造,这需要读取器不具有这种限制来表示。
ResourceBundle , ListResourceBundle , Properties
ResourceBundle.Controlparent| Constructor and Description |
|---|
PropertyResourceBundle(InputStream stream)
从 InputStream创建属性资源束。
|
PropertyResourceBundle(Reader reader)
从 Reader创建属性资源包。
|
| Modifier and Type | Method and Description |
|---|---|
Enumeration<String> |
getKeys()
返回一个
Enumeration包含在此按键
ResourceBundle及其父包。
|
Object |
handleGetObject(String key)
从此资源包获取给定键的对象。
|
protected Set<String> |
handleKeySet()
返回一个
Set的键
只包含在这个
ResourceBundle 。
|
clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, keySet, setParentpublic PropertyResourceBundle(InputStream stream) throws IOException
InputStream创建一个属性资源束。
使用此构造函数读取的属性文件必须编码为ISO-8859-1。
stream - 表示要读取的属性文件的InputStream。
IOException - 如果发生I / O错误
NullPointerException - 如果
stream为空
IllegalArgumentException - 如果
stream包含格式不正确的Unicode转义序列。
public PropertyResourceBundle(Reader reader) throws IOException
Reader创建一个属性资源束。
与构造函数PropertyResourceBundle(InputStream)不同,对输入属性文件的编码没有限制。
reader - 表示要读取的属性文件的Reader。
IOException - 如果发生I / O错误
NullPointerException - 如果
reader为空
IllegalArgumentException -如果错误的Unicode转义序列从出现
reader 。
public Object handleGetObject(String key)
ResourceBundle
handleGetObject在类别
ResourceBundle
key - 所需对象的关键
public Enumeration<String> getKeys()
Enumeration包含在此按键
ResourceBundle及其父包。
getKeys在类别
ResourceBundle
Enumeration的这个
ResourceBundle及其父包中包含的密钥。
ResourceBundle.keySet()
protected Set<String> handleKeySet()
Set的键
只包含在这个
ResourceBundle 。
handleKeySet在
ResourceBundle
Set的键只包含在这个
ResourceBundle
ResourceBundle.keySet()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.