import java.io.*;
import java.util.*;
class PropertiesText
{
public static void main(String[] args) throws IOException
{
BufferedReader bufr = new BufferedReader(new FileReader("info.txt"));
BufferedWriter bufw = new BufferedWriter(new FileWriter("info.txt"));
Properties prop = new Properties();
for(String str=bufr.readLine(); str!=null; str=bufr.readLine())
{
sop(str);
String[] strArr = str.split("=");
prop.setProperty(strArr[0],strArr[1]);
}
sop(prop);
prop.setProperty("wangwu","26");
Set<String> spn= prop.stringPropertyNames();
for(String key : spn)
{
bufw.write(key+"="+prop.getProperty(key));
bufw.newLine();
bufw.flush();
}
bufw.close();
bufr.close();
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
sop(str);//这句运行后没有输出。
sop(prop);//这句输出为{}
但是info.txt文件最后被改动了,里面只剩下数据wangwu=26
感觉for内的语句没有运行,循环直接就结束了,但是找不出哪里写错了 |