When I edited the ini last time (https://qiita.com/haniokasai/items/336afb29060601e74a41), the resulting ini file was messed up, so look for an alternative.
The library for this article may not work, so see my separate article. -> It becomes strange if there is an item with the same variable name.
intellij-deps-ini4j https://github.com/JetBrains/intellij-deps-ini4j inieditor-java https://github.com/nikhaldi/inieditor-java FastIni https://github.com/onlynight/FastIni java-configparser https://github.com/ASzc/java-configparser
It doesn't matter which one, but it seems to be easy to use IniEditor (https://github.com/nikhaldi/inieditor-java), I decided on you.
Maven
<!-- https://mvnrepository.com/artifact/org.ini4j/ini4j -->
<dependency>
<groupId>com.nikhaldimann</groupId>
<artifactId>inieditor</artifactId>
<version>r6</version>
</dependency>
IniEditor ini = new IniEditor();
ini.load("sample.ini");
ini.get("section","option");//example
//[section]
//option=example
ini.save("sample.ini");
IniEditor ini = new IniEditor();
ini.load("sample.ini");
ini.set("section","option");
ini.save("sample.ini");
IniEditor ini = new IniEditor();
ini.load("sample.ini");
ini.remove("section_name");
ini.save("sample.ini");
You can also add blank lines and comments.
Recommended Posts