当我更新属性文件时,注释也会随着数据而更新。是否有任何可能的方法来删除注释或更新没有注释的数据。
在这里,每次将日期时间戳作为注释附加时,我都会更新文件 4 次
#Thu May 19 17:53:42 GMT+05:30 2011
Key_1=DSA_1024
#Thu May 19 17:53:43 GMT+05:30 2011
Key_2=DSA_1024
#Thu May 19 17:53:43 GMT+05:30 2011
Key_3=DSA_1024
#Thu May 19 17:53:44 GMT+05:30 2011
Key_4=DSA_1024
code
Properties prop=new Properties();
String currentDirectary=System.getProperty("user.dir");
String path=currentDirectary+"/Resource/Key.Properties";
FileOutputStream out=new FileOutputStream(path,true);
prop.setProperty("keyName","DSA_1024");
prop.store(out, null);
我曾经不得不这样做,因为属性文件的使用者无法处理这些属性。该评论由store
方法定义良好,因此很容易跳过它:
Writer stringOut = new StringWriter();
properties.store(stringOut, null);
String string = stringOut.toString();
String sep = System.getProperty("line.separator");
out.write(string.substring(string.indexOf(sep) + sep.length()));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)