Just read in the file one line at a time and check for key words that you know will be in the ini file. So I guess there is more to this question than I am seeing.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Hi Cindy Glass, Thanks for your reply. I want to parse an ini file like IPAddress = "199...." Port = "1000" under the section say, Server1 The ini file also contains the following IpAddress = "199..." Port = "2000" under the section say, Server2 I could write a program to parse a file if it contains entries under no sections. Hope that i am clear to express my doubt. Could you help me to write a program according to this requirement? Thanks a lot...
Why don't you use a properties file. The API has support for that without having to code extra. a.properties content label=some value here Code String value = System.getProperty("label");
Thanks Paul Stevens and christopher foran. I had already looked into Properties class but i don't how it would be useful to parse an ini file which contains entries "under sections". I am able to use the Properties class if there is no section and if i have entries directly (i.e, key/value pairs like Port = "2000" ). If i have entries say Port = "2000" under sections Server1 and Server2, then how should i parse such a file? Thanks a lot...
You would need to change your key value. Your right it would not recognize a difference in port= under 2 different sections. You would need to say server1port= and server2port=. The alternative is code it all yourself.
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards