//Properties是一个持久的类 可以存在流中 或者从流中加载数据 //Properties是Hashtable的子类 实现了Map接口,Map集合 package cn.lijun.demo3; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Properties; import java.util.Set; public class PropertiesDemo { public static void main(String[] args) throws Exception { //fun(); //fun2(); fun3(); } //存 store(OutputStream out) store(Write w) public static void fun3() throws IOException{ Properties p=new Properties(); p.setProperty("name", "李登"); p.setProperty("age", "22"); p.setProperty("id", "001"); p.setProperty("email", "20101634510@qq.com"); p.setProperty("six", "女"); FileWriter f=new FileWriter("d:\\wang.properties"); p.store(f, ""); f.close(); } //Properties集合 特有方法 load(InputStream in) load(Reader r) //流对象读取键值对 public static void fun2() throws Exception{ Properties v=new Properties(); FileReader fr=new FileReader("d:\\wang.properties"); v.load(fr); fr.close(); System.out.println(v); } //关于Properties集 添加数据 获取数据 遍历数据 public static void fun(){ Properties v=new Properties(); v.setProperty("a", "1"); v.setProperty("b", "2"); v.setProperty("c", "3"); v.setProperty("d", "4"); String s=v.getProperty("a"); System.out.println(s); Set<String> se = v.stringPropertyNames(); for(String k: se){ System.out.println(k+" "+v.getProperty(k)); } } }