aspose file tools
The moose likes Java in General and the fly likes Best way to open a properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Best way to open a properties file" Watch "Best way to open a properties file" New topic
Author

Best way to open a properties file

sam White
Ranch Hand

Joined: Feb 18, 2011
Posts: 204
Hi,

Currently I am using the absolute path to open a properties file, shown as below:



In my PropertiesUtil constructor, I use the following code to open the file:



I am not writing a single program. The above code is written in my application package.
The problem of using this method is that, I have to pass in an absolute path of the properties file. How to use a relative path instead?

After some search, I found some example use class dot notation, eg. my.app.properties to locate a properties file.

I am not sure which way is better.

Any example and suggestion is very appreciated.


Thanks
S
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

If you only want to read from the file you can turn it into a resource, after which you can read it through Class.getResourceAsStream or ClassLoader.getResourceAsStream.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Best way to open a properties file
 
Similar Threads
read properties in my java application defined in spring bean "PropertyPlaceholderConfigurer"
Writing to properties file in WEB-INF
Opening a file with relative path
Loading properties file in WSAD 4.0.3
Loading Properties file