六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 24|回复: 0

java 删除propert文件数据

[复制链接]

升级  10%

1

主题

1

主题

1

主题

童生

Rank: 1

积分
5
 楼主| 发表于 2013-2-3 13:33:00 | 显示全部楼层 |阅读模式
public static void removeKey(String keyWord)
{
Map<String,String> map = new HashMap<String,String>();
Properties props = new Properties();
try
{
InputStream in = new BufferedInputStream(new FileInputStream("E://test.properties"));
props.load(in);
in.close();

OutputStream fos = new FileOutputStream("E://test.properties");
Enumeration<?> en = props.propertyNames();
while (en.hasMoreElements())
{
String key = (String) en.nextElement();
String Property = props.getProperty(key);
map.put(key, Property);
if(key.equals(keyWord))
{
map.remove(key);
continue;
}
}
props.clear();
props.putAll(map);
props.store(fos, "");
fos.close();
}
catch (Exception e)
{
Tracer.error("read property file fail");

}

}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表