首页 > 解决方案 > 如何使用 org.apache.commons.configuration.PropertiesConfiguration 在分隔符之间创建没有空格的属性?

问题描述

需要使用 org.apache.commons.configuration.PropertiesConfiguration 编写一个属性文件,它应该具有类似variablename=variablevalue的格式,并且分隔符之间没有空格。有没有办法使用 apache commons-configuration 来实现?

我目前的实现:

PropertiesConfiguration conf = new PropertiesConfiguration("test.properties");
conf.setProperty("key1","value1");
conf.save();

结果 :

key1 = value1

预期结果 :

key1=value1

标签: javaproperties-file

解决方案


文档在这里:https ://commons.apache.org/proper/commons-configuration/userguide_v1.10/howto_properties.html

未经测试,但我想这样做:

conf.getLayout().setGlobalSeparator("=");

推荐阅读