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
posted
0
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
posted
0
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
posted
0
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
posted
0
Much better. Thanks, James
rajesh katti
Greenhorn
Joined: May 24, 2001
Posts: 10
posted
0
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.