| 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: 16483
|
|
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
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
Gabriele
Try loading it using a URI:
http://docs.oracle.com/javase/6/docs/api/java/net/URI.html
|
 |
 |
|
|
subject: Loading a property file from a fixed folder in the filesystem
|
|
|