当我更新属性文件时,注释也会随着数据一起更新。是否有任何可能的方法来删除注释或更新数据而不带注释。
在这里,每次将日期时间戳附加为注释时,我都会更新文件 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
代码
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()));
关于java - 删除属性文件java中的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6058638/