删除属性文件java中的注释

Lal*_*and 8 java

当我更新属性文件时,注释也会沿着数据更新.有没有任何可能的方法来删除注释或更新数据而不发表评论.

每次将日期时间戳附加为注释时,我都会在此处更新文件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
Run Code Online (Sandbox Code Playgroud)

  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);
Run Code Online (Sandbox Code Playgroud)

Dav*_*veH 1

来自properties.store()的JavaDocs

如果注释参数不为空,则首先将 ASCII # 字符、注释字符串和行分隔符写入输出流。因此,评论可以充当识别评论。

接下来,始终写入注释行,由 ASCII # 字符、当前日期和时间(就好像由当前时间的 Date 的 toString 方法生成)以及由 Writer 生成的行分隔符组成。

我能想到的唯一选择是编写自己的OutputStream 实现来删除注释。(或者只是学会与他们一起生活:))