Is there any way to read INI files in Java by section, ie:
[Section 1]
var1=true
var2=false
[Section 2]
var1=false
Properties can get the variables, sure, but it seems to ignore the
Sections. Is there any good way to go about this?
Wojtek - 13 Mar 2007 20:38 GMT
jackroofman@gmail.com wrote :
> Is there any way to read INI files in Java by section, ie:
>
[quoted text clipped - 6 lines]
> Properties can get the variables, sure, but it seems to ignore the
> Sections. Is there any good way to go about this?
You pretty well have to write your own parser.
Most people separate sections within the key (variable) name:
section1.var1 = true
section1.var2 = false
section2.var1 = false
Or you can switch to XML which does understand nesting and has
available parsers.
But if you are working with existng files, then you need to write your
own. Basically:
- read a line
- trim the line
- if it starts with a [ and ends with a ] extract the section name
-- save the section name as the default section
- if it does not, split the line, then save the key/value into the
default section.
tada!

Signature
Wojtek :-)
Arne Vajhøj - 14 Mar 2007 00:45 GMT
> Is there any way to read INI files in Java by section, ie:
>
[quoted text clipped - 6 lines]
> Properties can get the variables, sure, but it seems to ignore the
> Sections. Is there any good way to go about this?
I would strongly recommend you to do it the Java way with either
regular properties files or XML.
But if you insist INI readers in Java has been written. Google finds:
http://www.codeproject.com/useritems/INIFile.asp
http://www.ubique.ch/code/inieditor/
Arne