This question already has an answer here:
I need to read a properties file and generate a Properties class in Java. I do so by using:
Properties props = new Properties();
props.load(new FileInputStream(args[0]));
for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
}
However, the properties returned by props.propertyName is not in the order of the original properties file. I understand that Properties are just old fashioned, non-generified Hashtables. I'm looking for a work around. Any idea? Thank you!
full implementation based on LinkedHashMap
Result:
Example from www.java2s.com should solve your problem.
And your code will change to:
Subclass Properties to memorize reading order and create an Enumeration that uses the ordered keys list ?