0

我有一个 .properties 文件,格式如下:

toto=titi
fofo=fifi
coco=cici
mama=momo
dada=didi

解析此文件时出现奇怪的显示。这是我正在使用的代码:

Properties prop = new Properties();
String fileLocation = "C:/myProperties.properties";
prop.load(new FileInputStream(fileLocation));

Iterator<Object> it = prop.keySet().iterator();
int line = 0;
while (it.hasNext()) 
{
       String propertyName = (String) it.next(); 
       if (propertyName.equals("coco"))
       {
          System.out.println("coco found at line : " + line);
          break;
       }

       else if (propertyName.equals("titi"))
       {
          System.out.println("Titi found at line : " + line);
          break;
       }

       line++;
}

你认为我会有什么输出?

我会在您回答后编辑问题。

谢谢你。

4

2 回答 2

5

Properties对象由Map实现支持,因此不要依赖属性的顺序。如果您还有其他要报告为“奇怪”的内容,请详细说明您的问题。:-)

于 2011-07-28T13:41:38.197 回答
0

Properties行号与使用散列存储元素无关。订单不被保留。

于 2011-07-28T13:42:09.953 回答