class hello {
public static void main(String[] args) throws IOException {
Properties prop = new Properties();
prop.load(new FileInputStream("info.txt"));
Enumeration<String> elements = (Enumeration<String>) prop.propertyNames();//枚举存储的的键和值
prop.setProperty("QQ", "987654");
prop.store(new FileOutputStream("info.txt"), "Lee");
//System.out.println(prop);
while(elements.hasMoreElements()) {
String key = elements.nextElement();
String value = prop.getProperty(key);
System.out.println(key + " = " + value);
}
}
原info信息:
运行结果:
更新后的info文件: