File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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

 
Consider Paul's rocket mass heater.
 
subject: Annoying properties file
 
Similar Threads
Common resource for all configurable parameters.
How not to hard-code file location in java?
build.properties - to have or not to have
How to access properties file from WEB-INF/ directory
using two properties files in struts