This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes Property files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Property files" Watch "Property files" New topic

Property files

Manhar Puri
Ranch Hand

Joined: Aug 23, 2005
Posts: 41
My question is more related to Web Applications. I want to store some properties in a property file. To read this file I need to provide the path to the file holding the properties.

My question is:

1) what are options in order to provide this path. I can myself think of two ways
a) Hard code the path in my class
b) Give the path as a system property
The second option has the disadvantage that if I provide my app as a war it cannot be deployed as is. I do not want to use first option for obvious reasons.

2) My second question I want to be able to read the properties and load them at startup of the application. Where should I put my code to do this? Also in case I want to read these properties per user session where should I put my code to read the properties.


Ben Souther

Joined: Dec 11, 2004
Posts: 13410

This How-to entry should be just what you're looking for.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bk Jacky
Ranch Hand

Joined: Jun 11, 2005
Posts: 74
just use this API
this system property point to dir that does not exit.It store ur property file path in system temp directory.So, there is no need to hard code it just make instance and access the file path.

just look at this API

Preparing SCWCD

SCJP1.4<br />SCWCD1.5<br />"Nothing is impossible"
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
Look for the getResourceAsStream method, it will let you place properties files in the same packages as your classes are. It will help you also with the war stuff because you will deploy your properties file in the same archive as your other java classes.

She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
I agree. Here's the link:
subject: Property files
It's not a secret anymore!