首页javapropertiesJava Collection - 如何从属性获取键列表

Java Collection - 如何从属性获取键列表

我们想知道如何从属性获取键列表。

propertyNames() method in Properties class combines the keys in the properties list with the keys in the defaults properties list passed into the constructor.

import java.io.FileInputStream; import java.util.Enumeration; import java.util.Properties; public class MainClass { public static void main(String args[]) throws Exception { Properties p = new Properties(); p.load(new FileInputStream("test.txt")); Enumeration e = p.propertyNames(); for (; e.hasMoreElements();) { System.out.println(e.nextElement()); } } }