package Zy;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
/*2.用代码实现以下需求:
(1)已知配置文件config.properties中有三个键值对
name=zhangsan
score=80
address=beijing
(2)使用IO字节流对象和Properties类结合使用,将配置文件中的score键的值修改为100*/
public class Zy02 {
public static void main(String[] args) throws IOException {
Properties pro=new Properties();
FileInputStream fis=new FileInputStream("d:\\java\\config.properties");
pro.load(fis);
Set<String> str=pro.stringPropertyNames();
for(String s:str){
if(s.equals("score")){
pro.setProperty(s, "100");
}else{
pro.setProperty(s, pro.getProperty(s));
}
System.out.println(s+"..."+pro.getProperty(s));
FileOutputStream fos=new FileOutputStream("d:\\java\\config.properties");
pro.store(fos, "message");
fos.close();
}
}
}