?
Solved

How to read a property from a properties file

Posted on 2007-04-03
2
Medium Priority
?
200 Views
Last Modified: 2013-11-24
I have a Servlet deployed on Tomcat. In my servlet I want to read a property from a properties file which is inside WEB-INF directory.
Please tell me how to do it.
0
Comment
Question by:rea_19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
boonleng earned 300 total points
ID: 18842351
String path = getServletContext().getRealPath("/WEB-INF/filename.properties");

Properties properties = new Properties();
properties.load(new FileInputStream(new File(path)));
0
 
LVL 10

Assisted Solution

by:Jaax
Jaax earned 200 total points
ID: 18842363
You could also try :
InputStream is = getClass( ).getResourceAsStream("filename.ext");
Properties properties = new Properties(is);


0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question