• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Property files

 
Manhar Puri
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,

Manhar.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Bk Jacky
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
just use this API

java.io.tmpdir
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

Bhupinder
SCJP1.4
Preparing SCWCD
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic