How to create properties without white spaces between separator using org.apache.commons.configuration.PropertiesConfiguration?

huangapple go评论83阅读模式
英文:

How to create properties without white spaces between separator using org.apache.commons.configuration.PropertiesConfiguration?

问题

Sure, here's the translated version:

需要使用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
英文:

Need to write a properties file using org.apache.commons.configuration.PropertiesConfiguration and it should have a format like variablename=variablevalue without having whitespaces between the separator. Is there a way to achieve that using apache commons-configuration?

My current implementation :

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

Result :

key1 = value1

Expected Result :

key1=value1

答案1

得分: 2

Docs are here: link

Untested but I imagine this does it:

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

英文:

Docs are here: https://commons.apache.org/proper/commons-configuration/userguide_v1.10/howto_properties.html

Untested but I imagine this does it:

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

huangapple
  • 本文由 发表于 2020年8月24日 17:40:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63558421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定