设为首页 加入收藏

TOP

Java中的Properties类的操作(二)
2015-07-16 12:55:41 来源: 作者: 【 】 浏览:7
Tags:Java Properties 操作
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


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python遍历文件夹和读写文件的方法 下一篇利用 Buck进行高效Android编译

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: