apache-commons-config PropertiesConfiguration:最后一个属性丢失后的注释 [英] apache-commons-config PropertiesConfiguration: comments after last property is lost

查看:31
本文介绍了apache-commons-config PropertiesConfiguration:最后一个属性丢失后的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PropertiesConfiguration 来编辑属性文件.这使我可以保留评论.除了最后一个键之后的注释外,一切正常..

I am using PropertiesConfiguration to edit property file. This allows me to retain comments. All works fine except for comments that comes after the last key..

例如输入文件

# *** A comment
GameCheck.no=No
**#  end coment**

输出如下.它丢失了最后一个键之后的评论

The output is as below. It lost comment that was after last key

# *** 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.
        }
    }
}

解决方法是在文件末尾添加一个虚拟属性.有正确的方法吗?

Work around is to add a dummy property towards the end of file. Is there a correct way?

推荐答案

这是一个应该在项目的 JIRA 中报告的错误 :)

This is a bug that should be reported in the project's JIRA :)

https://issues.apache.org/jira/browse/CONFIGURATION

这篇关于apache-commons-config PropertiesConfiguration:最后一个属性丢失后的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆