This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "properties file" Watch "properties file" New topic
Author

properties file

eric clark
Greenhorn

Joined: Jan 18, 2001
Posts: 16
im trying to read in a properties file, this werks like this:
Properties pr = new Properties();
File fname = new File("/tmp/deprop.properties");
FileInputStream input_stream = new FileInputStream(fname);
pr.load(input_stream);
String Name = pr.getProperty("Name");
now i wanna built a loop to readin all existing record and automatically built the strings out of it , like
properties file: name = eric jsp-page: string name = pr.getprop("name"), etc some1 could help me plz?
what i need to know,2 how do i write a properties file, is it the same way then reading it? thx
eric
[This message has been edited by eric clark (edited January 19, 2001).]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Since java.util.Properties is based on java.util.Hashtable, you can get an enumeration over all of the property names with:
Enumeration e = myProp.keys();
// or the easy to remember:
Enumeration e = myProp.propertyNames() ;
A Properties can list to a PrintStream like this:
myProp.list( System.out ) ; // a nice readable format
You can also save a Properites object to a file
with the store() method
A good reference such as Java in a Nutshell and/or copy of the JavaDocs is your friend.
Bill
 
Consider Paul's rocket mass heater.
 
subject: properties file
 
Similar Threads
File Letter Counter help
Java Cyrillic Characters
llegalArgumentException from servlet
how to read files in a directory on a local network
How to include a text file in the Javaservlet?