Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read a config file with sections using Java [duplicate]

Given a file containing this:

[upper]
a = A
b = B

[words]
1 = one
2 = two

How do I access these key/values with reference to their headers? Java's Properties() class only handles section-less files.

like image 398
tshepang Avatar asked Sep 16 '10 16:09

tshepang


2 Answers

Use the ini4j library (tutorial linked): http://ini4j.sourceforge.net/tutorial/

like image 67
Chris Dennett Avatar answered Sep 18 '22 00:09

Chris Dennett


If you are a fan of the Apache Commons offerings, they have a library just for you: Commons Configuration. Commons Configuration reads many more formats other than just the .INI style files.

like image 25
ssahmed555 Avatar answered Sep 22 '22 00:09

ssahmed555