LoginSignup
0
0

More than 3 years have passed since last update.

Javaでiniを編集するためのあれこれ。:inieditor-java

Last updated at Posted at 2019-06-25

前回(https://qiita.com/haniokasai/items/336afb29060601e74a41 ) でiniを編集したら、結果として生成されるiniファイルがめちゃくちゃだったので、代替案を探す。

注意

この記事のライブラリ、だめかもしれないので私の別記事を参照のこと。
ー>同一変数名の項目があるとおかしくなる。

intellij-deps-ini4j

inieditor-java

FastIni

java-configparser

別にどれでも構わないんだけど、使いやすそうな
IniEditor ( https://github.com/nikhaldi/inieditor-java ) 、君に決めた。

Maven

<!-- https://mvnrepository.com/artifact/org.ini4j/ini4j -->
<dependency>
  <groupId>com.nikhaldimann</groupId>
  <artifactId>inieditor</artifactId>
  <version>r6</version>
</dependency>

iniを読み出す

IniEditor ini = new IniEditor();
ini.load("sample.ini");
ini.get("セクション","オプション");//example
//[セクション]
//オプション=example
ini.save("sample.ini");

iniを書き込む

IniEditor ini = new IniEditor();
ini.load("sample.ini");
ini.set("セクション","オプション");
ini.save("sample.ini");

iniのセクションを消す

IniEditor ini = new IniEditor();
ini.load("sample.ini");        
ini.remove("section_name");
ini.save("sample.ini");

その他

ブランクの行やコメントも追加できるよ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0