LoginSignup
2
0

More than 3 years have passed since last update.

Javaでiniを編集する:ini4j編

Last updated at Posted at 2019-06-24

Javaでiniを編集するにはどうしたらよいか。

ini4j(https://mvnrepository.com/artifact/org.ini4j/ini4j) を使ってみる。

注意

ini4jがちゃんと動作しない可能性があるので、必ず振る舞いを確認すること。
ー>同一変数名の項目があるとおかしくなる。

Maven

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

注)ソースコードはhttps://ourcodeworld.com/articles/read/839/how-to-read-parse-from-and-write-to-ini-files-easily-in-javaより

iniを読み出す

Wini ini = new Wini(new File("C:\\Users\\sdkca\\Desktop\\myinifile.ini"));
int age = ini.get("owner", "age", int.class);
double height = ini.get("owner", "height", double.class);
String server = ini.get("database", "server");

iniを書き込む

Wini ini = new Wini(new File("C:\\Users\\sdkca\\Desktop\\myinifile.ini"));

ini.put("block_name", "property_name", "value");
ini.put("block_name", "property_name_2", 45.6);
ini.store();

iniのセクションを消す

Wini ini = new Wini(new File("C:\\Users\\sdkca\\Desktop\\myinifile.ini"));

ini.remove("section_name");
ini.store();

Reference

https://ourcodeworld.com/articles/read/839/how-to-read-parse-from-and-write-to-ini-files-easily-in-java
http://tmyk-h.hateblo.jp/entry/2014/01/31/014937
https://codeday.me/jp/qa/20181218/35503.html

2
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
2
0