operties(String filePath) throws IOException{ ? ? ? ? Properties pps = new Properties(); ? ? ? ? InputStream in = new BufferedInputStream(new FileInputStream(filePath)); ? ? ? ? pps.load(in); ? ? ? ? Enumeration num = pps.propertyNames(); //获取配置文件中的所有属性名enumeration ? ? ? ? while(num.hasMoreElements()){ ? ? ? ? ? ? String key= (String)num.nextElement(); ? ? ? ? ? ? String value=pps.getProperty(key); ? ? ? ? ? ? System.out.println(key + "=" + value); ? ? ? ? } ? ? } ? ? ? ? //写入Properties信息 ? ? public static void WriteProperties(String filePath,String pKey,String pValue) throws IOException { ? ? ? ? Properties pps = new Properties(); ? ? ? ? InputStream in= new FileInputStream(filePath); ? ? ? ? pps.load(in); ? ? ? ? OutputStream out = new FileOutputStream(filePath); ? ? ? ? pps.setProperty(pKey, pValue); ? ? ? ? pps.store(out, "Update " + pKey + " name"); ? ? } }
结果:test.properties文件
#Update add2 name #Tue Jun 30 17:07:55 CST 2015 age=23 name=linyuhuan weight=140 add2=2121 long=212
|