Properties 读取资料和保存文件

Properties 读取文件和保存文件
public static void main(String[] args) throws IOException {
File f = new File("./32.txt");
if (f.exists()) {
System.out.println("文件存在!");
}
try {
//打开文件
FileInputStream in = new FileInputStream(f);
InputStreamReader isr = new InputStreamReader(in, "UTF-8");
Properties props = new Properties();
props.load(isr);

in.close();//流打开了记得关
Iterator itr = props.entrySet().iterator();
int i = 0;
        while (itr.hasNext()){
            Entry e = (Entry)itr.next();
            String keyString = (String) e.getKey();
            String value = (String) e.getValue();
            System.out.println(keyString);
            System.out.println(value);
        }
String value = props.getProperty("MIDlet-Jar-URL");
System.out.println("value:" + value);
props.setProperty("MIDlet-Jar-URL", value);
System.out.println("newvalue:"
+ props.getProperty("MIDlet-Jar-URL"));
System.out.println(props);
try {
//保存文件
File file = new File("./12.txt");
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter isrs = new OutputStreamWriter(out, "UTF-8");
props.store(isrs, null);
out.close();
System.out.println();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}



本人试过用Properties读取大文件的属性值(本来替换第一人称那个程序想用这种方法读取文件的),结果顺序全部打乱,有些还读不了,可能和里面的缓冲区有关吧。