第二个参数是对列表参数的描述,可以给值,也可以给null,面试题可能是涉及到
package com.heima.otherio;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
public class Demo10_Properties {
/**
* @param args
* Properties是Hashtable的子类
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
Properties prop = new Properties();
prop.load(new FileInputStream("config.properties")); //将文件上的键值对读取到集合中
prop.setProperty("tel", "18912345678");//修改tel属性的值,但是此时只是改的内存中的数据
prop.store(new FileOutputStream("config.properties"), null);//第二个参数是对列表参数的描述,可以给值,也可以给null
System.out.println(prop);
}
} |
|