没有空格的Java ini [英] Java ini without spaces

查看:69
本文介绍了没有空格的Java ini的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ini4j和inieditor从Java更改ini配置文件。不幸的是,这两个库都重写了=符号以外的文件放置空格。

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...

这破坏了它试图配置的C库。

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

我看到ini4j有一个名为FancyIniFormatter的东西,显然可以做到这一点,但我无法找到有关用法的适当文档... http://www.jarvana.com/jarvana/view/org/ini4j/ini4j/0.4.0/ini4j-0.4.0.jar!/org/ini4j/addon/FancyIniFormatter.class?classDetails=好的

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.

谢谢

推荐答案

ini4j格式化程序基于 Config 。在此配置中,分隔符设置为char'=',但在类中IiniFormatter 中,您还有另一个分隔符声明,即字符串 =。当 Config#isStrictOperator 设置为false时,将使用此类型。

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);

这篇关于没有空格的Java ini的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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