import java.util.*;
import java.io.*;public class UseProperties {
public static void main(String args[]) throws Exception {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream("ApplicationResources.properties");
prop.load(fis);
prop.list(System.out);
}
}我用上面的程序读取ApplicationResources.properties文件的内容,读出的结果顺序就乱了,不是按照原有顺序排列,谁知道怎么回事,知道的请解答下。谢谢!!!

解决方案 »

  1.   

    Properties本身就是无序的。想有序可以自己实现。public static void main(String[] args) throws Exception{
    Map<String,String> map = new LinkedHashMap<String,String>();
    FileInputStream fis = new FileInputStream("ApplicationResources.properties");
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String pair = "";
    while((pair=br.readLine())!=null){
    String key = pair.substring(0,pair.indexOf("="));
    String value = pair.substring(pair.indexOf("=")+1);
    map.put(key, value);
    }
    fis.close();
    br.close();
    System.out.println(map);
    }
      

  2.   

    Properties extend Hashtable, Hashtable implement Map.   
    所以无序哈
      

  3.   


    这段代码我在eclipse下编译通不过,在命令行下可以编译,但运行时出错了
      

  4.   

    你根本不需要排序呀
    读取Properties文件的时候按照map的形式存取 
    实在想不明白为什么有按顺序···