Tuesday 23 April 2013

How to iterate Properties Files in Java?


1. Properties props = System.getProperties();
for (String key : props .stringPropertyNames())
{
   System.out.println(key + " = " + props .getProperty(key));
}

2. Properties props = System.getProperties();
Enumeration e = props.propertyNames();

while (e.hasMoreElements())
{
   String key = (String) e.nextElement();
   System.out.println(key + " = " + props.getProperty(key));
}

3. Properties props = System.getProperties();
SortedMap sortedSystemProperties = new TreeMap(props);
Set keySet = sortedSystemProperties.keySet();
Iterator iterator = keySet.iterator();
while (iterator.hasNext())
{
   String key = (String) iterator.next();
   System.out.println(key + " = " + props .getProperty(key));
}

No comments:

Post a Comment