A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide 1Z0-808
this week in the
How to get the path of property file.
Joined: Oct 09, 2004
Sep 01, 2007 01:27:00
I have one sample project named as TMS, In my "WEB-INF/conf" foler contains database.properties file. It contains
hostname = some host name
url= some url
This project contains only one database.properties file.
file, I want to get hostname and url from that property file.
Properties props=new Properties () ;
props.load ( new
( new File ("E:\\Workspace\\TMS\\WebRoot\\WEB-INF\\conf\\database.properties"))) ;
String val = props.getProperty ("Host Name Is :"+ host ) ;
Using the above code, I have got both hostname and url.
But my problem is, How to get the current project database.properties file path.
Because in the above path name is hard coded.
So How we get current project database.properties file path?
Thank You<br />Edward
Francois Dang Ngoc
Joined: Sep 02, 2007
Sep 02, 2007 23:19:00
You can use the method getServletContext() as follows:
is = getServletContext().getResourceAsStream ("/WEB-INF/conf/database.properties");
Properties props = new Properties();
out.println("HOST: " + props.getProperty("host") + " URL: " + props.getProperty("url"));
Hope it helps,
Joined: Aug 31, 2007
Sep 05, 2007 07:10:00
How about using
You just need to know the property file name.
It is sorta covered in the
JavaRanch Style Guide
subject: How to get the path of property file.
deploying in tomcat 6
Accessing a context.xml from a virtualhost
Want to change Application Property at startup
tomcat connection pooling
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015