java - 如何在不写日期和时间注释的情况下在属性文件中写入数据

use*_*945 1 java

我想使用java在属性文件中写入数据。我可以使用java在文件中写入数据,但默认情况下我每次都会收到日期和时间等注释。

请任何人建议如何使用java避免或删除properties文件中的注释

这是我的代码:

File file = new File("C:/Software/app.properties");
Properties properties = new Properties();
FileOutputStream fileOut = new FileOutputStream(file, true);
properties.setProperty(""+data.split(Constants.DATA_SPLIT)[1]+"", value);
properties.store(fileOut, null);
fileOut.close();
Run Code Online (Sandbox Code Playgroud)

我的 o/p 是 O/put 是:

#Wed Jun 04 13:23:54 IST 2014 CurrnerURL=J;SLDAJGLLASJGKPJ #Wed Jun 04 13:25:54 IST 2014 CurrnerURL=J;SLDAJGLLASJGKPJ

我不想在文件中评论会话。请建议我。

Jen*_*ens 5

默认情况下是不可能的。

如果你需要这个,你必须覆盖java.util.Properties 原始类的部分 Here 的方法 store0 。

private void store0(BufferedWriter bw, String comments, boolean escUnicode)
         throws IOException
     {
         if (comments != null) {
             writeComments(bw, comments);
         }
         bw.write("#" + new Date().toString());
         bw.newLine();
         synchronized (this) {
             for (Enumeration e = keys(); e.hasMoreElements();) {
                 String key = (String)e.nextElement();
                 String val = (String)get(key);
                 key = saveConvert(key, true, escUnicode);
                 /* No need to escape embedded and trailing spaces for value, hence
                  * pass false to flag.
                  */
                 val = saveConvert(val, false, escUnicode);
                 bw.write(key + "=" + val);
                 bw.newLine();
             }
         }
         bw.flush();
     }
Run Code Online (Sandbox Code Playgroud)