apache-commons-config PropertiesConfiguration:丢失最后一个属性后的注释
我正在使用PropertiesConfiguration来编辑属性文件。 这允许我保留评论。 除了最后一个键之后的注释,一切正常。
例如输入文件
# *** A comment GameCheck.no=No **# end coment**
输出如下。 它失去了最后一把钥匙之后的评论
# *** A comment GameCheck.no = myvar
代码如下。
package trials; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.PropertiesConfigurationLayout; import java.io.FileWriter; import java.io.IOException; public class EditVersion { public static void main(String[] args) { try { PropertiesConfiguration config = new PropertiesConfiguration("C:\\try\\in.properties"); config.setProperty("application.version", "myvar"); PropertiesConfigurationLayout layout = config.getLayout(); config.save( new FileWriter( "c:/try/out.props")); } catch (ConfigurationException e) { } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }
解决方法是在文件末尾添加虚拟属性。 有正确的方法吗?
这是一个应该在项目的JIRA中报告的错误:)
您可以尝试从**# end coment**
的开头删除**# end coment**
,以防它**# end coment**
。
如果在最后一行之后有空行,请检查是否有帮助。
- Google Guava vs. Apache Commons
- Struts2 jQuery struts-plugin.xml无效
- org.apache.commons.net.ftp.FTPClient listFiles()的问题
- 如何将字符串参数传递给使用Apache Commons Exec启动的可执行文件?
- Apache Commons CSV库中封装的标记和分隔符之间的char无效
- Apache Commons DbUtils的替代轻量级JDBC帮助库
- 使用Apache Commons电子邮件发送邮件时出现问题
- org.apache.commons.dbcp.DelegatingPreparedStatement已关闭
- Java中的链表有快速连接方法吗?