java.util.ResourceBundle.getKeys()%uA0方法返回键的枚举。
声明
以下是java.util.ResourceBundle.getKeys()方法的声明
public abstract Enumeration<String> getKeys()
参数
-
NA
返回值
此方法返回包含在此ResourceBundle及其父包中的键的枚举。
异常
-
NA
例子
下面的例子显示java.util.ResourceBundle.getKeys()方法的用法。
package com.yiibai 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