Solved

How to read a property from a properties file

Posted on 2007-04-03
2
173 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
2 Comments
 
LVL 14

Accepted Solution

by:
boonleng earned 75 total points
Comment Utility
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 50 total points
Comment Utility
You could also try :
InputStream is = getClass( ).getResourceAsStream("filename.ext");
Properties properties = new Properties(is);


0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now