Categorically reading INI Files

J

jackroofman

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?
 
W

Wojtek

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?

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!
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top