• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

To read an ini file

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone help me to read a configuration file (i.e., ini file) which have section names and then entries
Thanks...
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checkout the java.util.Properties class. Sounds like this does alot of the work for you.
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic