This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Annoying properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Annoying properties file" Watch "Annoying properties file" New topic
Author

Annoying properties file

James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Has anyone got an example of code which extracts a string from a properties file (i.e. a terxt file which contains pairs of values) and prints it out?
I'm having trouble getting such a servlet working.
thanks
James
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Hai James Hewitt,
I hope you are using java.util.Properties.I think you have problems with the path in which your Property file is situated.Try it by giving the complete path of the file when you are loading the property file

I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Nope, that doesn't seem to fix it. I reckon I'm making a really simple mistake, it's just not obvious to me. Just need to see a simple implementation in a piece of sample code, and I'm sure it'll all be clear.
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Hai James,
See this code and try this
import java.util.Properties;
import java.io.FileInputStream;
public class PropertyExample
{
Properties simpleProperties;
public PropertyExample() throws Exception
{
FileInputStream myFile=new FileInputStream("/home/james/project/files/Info.properties");
simpleProperties=new Properties();
simpleProperties.load(myFile);
}
public String getProperty(String key)
{
return simpleProperties.getProperty(key);
}
}
James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Much better.
Thanks,
James
rajesh katti
Greenhorn

Joined: May 24, 2001
Posts: 10

Hi James,
Just try this....I had probs with properties file..so I tried this with "ResourceBundle" object from util. It is similar to the properties file..Just 1 line of code..
A) Servlet
import java.util.*;
ResourceBundle messages =
ResourceBundle.getBundle("Global_file");
fname = messages.getString("fname");
B)Global_file.properties file
fname = Rajesh
lname = Katti
If u face any probs..do let me know.

Rajesh

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Annoying properties file
 
Similar Threads
build.properties - to have or not to have
How not to hard-code file location in java?
Common resource for all configurable parameters.
using two properties files in struts
How to access properties file from WEB-INF/ directory