Home arrow static arrow Java Programming [Archive] - variables
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - variables
This topic has 5 replies on 1 page.

Posts:38
Registered: 5/28/04
variables  
Aug 4, 2004 2:20 AM



 
i want a way of setting certain varibales without a user having to open the java file, maybe just opening a text file.

for example i have the following

string server = "andrews";
string folder = "andrewsfiles"
String file = "andrew.doc";

i want the user to be able to configure this as the server name, directory and filename may
need to be changed.

is there a way of creating a text file containing the varibales and what they are set to
that the java file reads when it is run

any ideas

Andy
 

Posts:5,965
Registered: 5/17/03
Re: variables  
Aug 4, 2004 2:24 AM (reply 1 of 5)



 
You'll have to read the textfile into your program and then parse the lines for the information you expect to find.
 

Posts:4
Registered: 9/30/03
Re: variables  
Aug 4, 2004 2:26 AM (reply 2 of 5)



 
You may want to use the class java.util.Properties to accomplish that task:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html
 

Posts:5,965
Registered: 5/17/03
Re: variables  
Aug 4, 2004 2:27 AM (reply 3 of 5)



 
This shows how you can read a textfile line by line,

http://javaalmanac.com/egs/java.io/ReadLinesFromFile.html
 

Posts:38
Registered: 5/28/04
Re: variables  
Aug 4, 2004 2:34 AM (reply 4 of 5)



 
cheers, i currently have it doing it that way
using the buffered reader and readline + parsing
i was just wondering if there was an easier way
as it is a bit long winded

cheers for the replys :)
 

Posts:13
Registered: 8/3/04
Re: variables  
Aug 4, 2004 2:46 AM (reply 5 of 5)



 
Check out the java.util.Properties class, like someone mentioned earlier. It's especially designed for that kind of situation and is easy to use.
 
This topic has 5 replies on 1 page.