• 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
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

how to use relative path in files?

 
Greenhorn
Posts: 4
Java ME Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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(){
try{
p = new Properties();

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

p.load(fis);

return true;

}
catch(Exception e){

return false;
}

}

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

try{
if(loadDBProperties()){

Class.forName(p.getProperty("db.driver"));

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........
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Place the file under the WEB-INF folder and use the ServletContext.getResourceAsStream() method to open a stream to the file.
 
Ranch Hand
Posts: 30
Spring Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using spring framework, if not please use Resource Bundle and put the properties file into web-inf classes folder.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic