Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to ini file

Status
Not open for further replies.

Scouseman

Technical User
Mar 25, 2003
22
US
Hi

I wonder if someone can help me. I have 2 programs one written in Visual Basic and one in Java, I have coded my Visual Basic basic program to read the value of a variable from within an ini file. Can somebody please explain how I can write to a ini file from within java.

E.g I have created an ini file called test1.ini and inside the file the following text appears

[Data]
rate=.092

I need the code from within java to alter the value of rate.

Hope someone can help

Thanks

Scouseman
 
Java has no native functionality for handling .ini file formats. Therefore you have to write your own code to process the file. There are many stream classes in the java.io package that can be used to read/write files like LineNumberReader etc. Also there may be some file I/O tutorials at java.sun.com

-pete
 
Since you have written the 2 programs yourself, it might be easier to switch to an XML-file instead of an ini-file.
 
Thanks everyone for your replies..

Hologram, what is the advantages of using XML instead of ini? Is it easy to implement?

Thanks

Scouseman
 
XML can represent hierarchal data and multiple named values for a single entity. Try to do that in an .ini format.

It is very easy, like anything else, once you know it. [wink]



-pete
 
i second pete. xml is preferred over ini. nio(pronounced new io) is preferred over io since it takes advantage of the new hardware.

~za~
You can't bring back a dead thread!
 
Hi all

Thanks for all the advise.
I have done alot of research regarding XML, as I have never used it before.

I think I am getting myself a little confused. I have found an excellent VB6 example on the net which implements MS-XML-
The only thing is when I go to the sun java forum they seem to be implmenting a different version of XML (JAX)

I am only wanting to pass 2 integer values and the code I am trying to use appears very complicating. Are these 2 versions of XML compatible?


In my Java code do I need to continually rewriting the whole file or is it possible to find a particular section and replace the required value

Thanks again for your time

Scouseman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top