java 删除propert文件数据

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");

}

}

你可能感兴趣的:(java)