Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to read a property from a properties file

Posted on 2007-04-03
2
Medium Priority
?
207 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

609 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