Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to get the path of property file.

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have one sample project named as TMS, In my "WEB-INF/conf" foler contains database.properties file. It contains

e.g
hostname = some host name
url= some url

This project contains only one database.properties file.
In java file, I want to get hostname and url from that property file.

e.g.

Properties props=new Properties () ;
props.load ( new FileInputStream ( new File ("E:\\Workspace\\TMS\\WebRoot\\WEB-INF\\conf\\database.properties"))) ;

String host= "hostname";
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?

Thanking you.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Edward,

You can use the method getServletContext() as follows:

InputStream is = getServletContext().getResourceAsStream ("/WEB-INF/conf/database.properties");
Properties props = new Properties();
props.load(is);
out.println("HOST: " + props.getProperty("host") + " URL: " + props.getProperty("url"));

Hope it helps,

Cheers,

Francois
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using ResourceBundle?
You just need to know the property file name.

Apple Man
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic