如何以原始顺序读取java中的属性文件 [英] How to read a properties file in java in the original order
问题描述
我需要读取一个属性文件并在Java中生成一个 Properties 类。我这样做是通过使用:
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();) {
}
但是,props.propertyName返回的属性不是原始属性文件的顺序。我知道 Properties 只是老式的,非泛化的Hashtables。我正在寻找一个解决方案。任何的想法?谢谢!
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!
推荐答案
您可能希望实现具有类似功能的属性类。
您将无法获得订单,因为您已经指出,它使用 Hashtable
。
You may want to implement your own Properties class with similar functionalities.
It will not be possible for you to obtain the order since, as you already pointed out, it uses Hashtable
.
这篇关于如何以原始顺序读取java中的属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!