从Java Properties文件按顺序提取值? [英] Pulling values from a Java Properties file in order?

查看:511
本文介绍了从Java Properties文件按顺序提取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性文件,其中值的顺序很重要。我想能够遍历属性文件,并根据原始文件的顺序输出值。



但是,由于支持的属性文件,如果我错了,纠正我,一个不维护插入顺序的地图,迭代器返回值

$



<$ p

枚举名称= propfile.propertyNames();
while(names.hasMoreElements()){
String name =(String)names.nextElement();
// do stuff
}

解决方案

如果你可以改变属性名称,你可以在它们前面加一个数字或其他可排序前缀,然后排序属性KeySet。


I have a properties file where the order of the values is important. I want to be able to iterate through the properties file and output the values based on the order of the original file.

However, since the Properties file is backed by, correct me if I'm wrong, a Map that does not maintain insertion order, the iterator returns the values in the wrong order.

Here is the code I'm using

    Enumeration names = propfile.propertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        //do stuff
    }

Is there anyway to get the Properties back in order short of writting my own custom file parser?

解决方案

If you can alter the property names your could prefix them with a numeral or other sortable prefix and then sort the Properties KeySet.

这篇关于从Java Properties文件按顺序提取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆