我有一个包含许多.properties文件的文件夹,每个文件都有TimeStamp评论(#Wed Sep 07 10:47:35 CEST 2016)。我需要使用java删除每个.properties文件中存在的这个注释时间戳(#Wed Sep 07 07:47:35 CEST 2016)。因为我是.properties的新手,不知道如何删除.properties文件中的注释。 请帮帮我。
Properties prop=new Properties(); FileOutputStream out = new FileOutputStream("C:\\PracticeElement__i22_messages.properties");
ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
prop.store(arrayOut, null);
String string = new String(arrayOut.toByteArray(), "8859_1");
String sep = System.getProperty("line.separator");
String content = string.substring(string.indexOf(sep) + sep.length());
out.write(content.getBytes("8859_1"));
答案 0 :(得分:0)
在您的代码中,您需要在存储arrayOut之前加载属性文件 请尝试此代码,
Designer | Developer | Coder
---------+-----------+--------
X | A | Y
Null | B | Z
注意:这将删除属性文件中的整个注释。