Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Categorically reading INI Files

Thread view: 
jackroofman@gmail.com - 13 Mar 2007 19:20 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.