Java ini without spaces

和自甴很熟 提交于 2020-01-06 08:11:52

问题


I have attempted to use ini4j and inieditor to alter from java an ini configuration file. Unfortunately, both libraries rewrite the file putting spaces besides the = sign...

This breaks that C library it is attempting to configure.

#This is a sample of what I get:
[root]
role = administrator
last_login = 2003-05-16

#This is what I need:
[root]
role=administrator
last_login=2003-05-16

I saw that ini4j has something named FancyIniFormatter which apparently does just that but I was unable to find proper documentation on the usage... http://www.jarvana.com/jarvana/view/org/ini4j/ini4j/0.4.0/ini4j-0.4.0.jar!/org/ini4j/addon/FancyIniFormatter.class?classDetails=ok

I am hoping to do this natively from the library but I can always load up the file and perform a regex operation but if I can avoid it that would be great.

Thanks,


回答1:


The ini4j formater is based on Config. In this config the separator is set to char '=', but in the class IiniFormatter you have another declaration of separator as string " = ". This type is used when Config#isStrictOperator is set to false.

Config config = new Config();
  config.setStrictOperator(true);

IniFormmater formater = IniFormmater.newInstance(out, config);


来源:https://stackoverflow.com/questions/17859328/java-ini-without-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!