黑马程序员技术交流社区

标题: 切记properties类store第二个参数 [打印本页]

作者: 牛牛范儿    时间: 2016-3-30 22:40
标题: 切记properties类store第二个参数
第二个参数是对列表参数的描述,可以给值,也可以给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);
        }       
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2