This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Loading a property file from a fixed folder in the filesystem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Loading a property file from a fixed folder in the filesystem" Watch "Loading a property file from a fixed folder in the filesystem" New topic
Author

Loading a property file from a fixed folder in the filesystem

Gabriele Giambartolomei
Greenhorn

Joined: Nov 17, 2011
Posts: 8
Hello folks,

I have a file called outbound.properties that I load in my Java application. This file at the moment is in the /src directory of my project and I load it using something like:
InputStream input = MailService.class.getResourceAsStream(Constants.Session.OUTBOUND_PROPERTIES_FILE); where OUTBOUND_PROPERTIES_FILE is define as "/outbound.properties/ and is the name of the file and it all work prefectly !
Now, I would like to put the property file outside my project folder, for example in the folder C:\data of my filesystem. I tried to change the name of the OUTBOUND_PROPERTIES_FILE in "C:\data" but I get a
WARNING: Configuration file:/data/outbound.properties not found, using defaults. Of course the file it is there !

How can I load a java property file from an absolute path in my filesystem, for example C:\data\myConfigFiles ?

Thanks a lot in advance for your help !
Gabriele
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Like this:

The Class.getResourceAsStream() method gets an input stream from a resource which is defined relative to your classpath. That isn't what you want.
Gabriele Giambartolomei
Greenhorn

Joined: Nov 17, 2011
Posts: 8
Hello Paul,

many thanks for your quick reply ! It was driving me crazy ! I will try to do it the way you seggested me and see how it goes.
Thanks a lot !
Gabriele
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Gabriele

Try loading it using a URI:

http://docs.oracle.com/javase/6/docs/api/java/net/URI.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading a property file from a fixed folder in the filesystem
 
Similar Threads
Build problem when including third party jars in classpath using ant
ant not deploying on Tomcat 7
Complie time using custom classloader for decryption.
Forte4j\Development\examples
loading property files across modules(WSAD)