Click to See Complete Forum and Search --> : Writing to an ini file?!
WVTR
Dec 6th, 2000, 02:35 AM
I'm new to Java. Give me detailed help or links! Thanks!
Problem:
I have to store data into a file. The data in the file should be stored like you would store data in an ini-file. In VB you can do this by calling:
BOOL WriteProfileString( LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue );
and retrieving data by calling:
CString GetProfileString( LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL );
Is there a class or method that does the same thing??
Thanks!
WVTR
I haven't seen the functions you are looking for but that doesn't mean they don't exist.
Writing to an ini file is the same as writing to a file. See the similar posts about that and http://java.sun.com . I gave specific links before.
Remember that Java is supposed to be platform independent. So the specific functions you seek (although they may exist) would take away from this independency goal.
Also, the "Sand Box" rules for applets is a security concern. Applications can easily do file I/O.
Windows ini and Windows registry would be platform dependent on MS Windows.
noone
Dec 8th, 2000, 11:19 PM
The Properties class should do what you want. It stores a set of name value pairs and you can load or store it from a file with a simple method call.
http://java.sun.com/docs/books/tutorial/essential/attributes/properties.html
More information can be found in the JDK API Docs for the Properties class.
WVTR
Dec 12th, 2000, 02:34 AM
Thnx 'VirtuallyVB' and 'noone' for the replies! I'm still looking for a java class that does the read from and write to a file with the structure of a ini-file!
Your answers confirmed what I thought. There isn't a java class yet (that I know) that can write to/read from an ini-file like in VB, Installshield,...:
[Groupname1]
Keyname1 = value
Keyname2 = value
[Groupname2]
Keyname1 = value
Keyname2 = value
The properties class is usefull but it doesn't know Groupnames. That's a pity!!! I need the same structure as in the example above.
There is a less practical solution (but it works), such as:
Total_Groups = 2
Groupnames = Groupname1, Groupname2
Groupname1_Keyname1 = value
Groupname1_Keyname2 = value
Groupname2_Keyname1 = value
Groupname2_Keyname2 = value
I agree with 'VirtuallyVB' that java should be platform independent. I don't agree with his statement that the functions (if they should exists) for reading from and writing to a file with the same structure as an ini-file would take away the java platform independency goal. On the contrary, I think if there is something easy to use and good (common to windows or other platform), why not try to implement/reuse it on another platform.
WVTR
I agree with you WVTR, that those functions make ini type file I/O very easy to use and it would be nice to have them in Java (assuming they do not already exist); but if we keep talking about functions that are only available on one or two (and probably just one) platform (meaning MS Windows--not Win3.1,3.11,for Networks,95,98,2000Standard, 2000Professional, etc), then we are not talking about platform independence.
noone
Dec 14th, 2000, 08:16 PM
Well adding reading and writing of ini files shouldn't really make Java less platform independant, you should be able to write your own class to do so without too much trouble, you probably just need to wrap it around the Properties file.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.