Java.util.ResourceBundle.getKeys() 方法
描述
java.util.ResourceBundle.getKeys() 方法返回键的枚举。
声明
以下是 java.util.ResourceBundle.getKeys() 方法的声明
public abstract Enumeration<String> getKeys()
参数
NA
返回值
此方法返回此 ResourceBundle 及其父捆绑包中包含的键的枚举。
异常
NA
示例
下面的例子展示了 java.util.ResourceBundle.getKeys() 方法的使用。
package com.tutorialspoint;
import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
public class ResourceBundleDemo {
public static void main(String[] args) {
// create a new ResourceBundle with specified locale
ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
// print the text assigned to key "hello"
System.out.println("" + bundle.getString("hello"));
// get the keys
Enumeration<String> enumeration = bundle.getKeys();
// print all the keys
while (enumeration.hasMoreElements()) {
System.out.println("" + enumeration.nextElement());
}
}
}
假设我们在您的 CLASSPATH 中有一个可用的资源文件 hello_en_US.properties,其内容如下。 该文件将用作我们示例程序的输入 −
hello = Hello World! bye = Goodbye World! morning = Good Morning World!
让我们编译并运行上面的程序,这将产生以下结果 −
Hello World! hello bye morning

