Mega Code Archive

 
Categories / Java Tutorial / Collections
 

Getting a key List from Properties

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());     }   } } //File: test.txt /* foo:bar one two three=four five  six seven eight nine ten */ five two one three nine foo