Properties类属性集合
Properties类属性集合
特点:
1.存储属性名和属性值
2.属性名和属性值都是字符串类型
3.没有泛型
4.和流有关
package com.tiedandan.IO流.Properties集合; import java.io.*; import java.util.Properties; import java.util.Set; public class application { public static void main(String[] args) throws IOException { //创建集合 Properties properties = new Properties(); //添加数据 properties.setProperty("username","张三"); properties.setProperty("age","20"); //输出 System.out.println(properties.toString()); //遍历 Set<String> pronames =properties.stringPropertyNames(); for (String proname : pronames) { System.out.println(proname+"--"+properties.getProperty(proname)); } //和流有关的方法 //---------list方法------ // //2.store方法保存 // //3.load方法加载 Properties properties2 = new Properties(); FileInputStream fis = new FileInputStream("d:\\store.properties"); properties2.load(fis); fis.close(); System.out.println(properties2.toString()); } }