This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to use relative path in files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to use relative path in files?" Watch "how to use relative path in files?" New topic

how to use relative path in files?

narendra cheeterala

Joined: Oct 09, 2012
Posts: 4

i am designing a web project in MVC pattern, so i created a properties file & used that file to load properties for database.
my code is:

public static boolean loadDBProperties(){
p = new Properties();

fis = new FileInputStream("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/LoginApplicationMVC1/WEB-INF/properties/");


return true;

catch(Exception e){

return false;


//creating and returning connection object
public static Connection getConnection()



con = DriverManager.getConnection(p.getProperty("db.url"),p.getProperty("db.userid"),p.getProperty("db.password"));

return con;

return null;

catch(Exception e){

return null;

In that code how to use relative path to load properties file........
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63352

Place the file under the WEB-INF folder and use the ServletContext.getResourceAsStream() method to open a stream to the file.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pablo Abbate
Ranch Hand

Joined: Aug 06, 2012
Posts: 30

Are you using spring framework, if not please use Resource Bundle and put the properties file into web-inf classes folder.

Nissi Group, Posicionamiento Web, Desarrollo de Software, DiseƱo Web
Blog , LinkedIn
I agree. Here's the link:
subject: how to use relative path in files?
It's not a secret anymore!