Solved

How to read a property from a properties file

Posted on 2007-04-03
2
183 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
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 50 total points
ID: 18842363
You could also try :
InputStream is = getClass( ).getResourceAsStream("filename.ext");
Properties properties = new Properties(is);


0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Timer (static) 9 45
Spring Framework HTTPSession management 1 36
even odd program using while loop 3 44
Which non-HTML GUI front end to use with Java? 3 22
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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 …

831 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