Lehane
Lehane

Reputation: 48688

Current directory in java properties file

Is there any way of specifying the current directory in a java properties file?

i.e. something like:

fileLocation={currentDir}/fileName.txt

Upvotes: 7

Views: 13550

Answers (3)

Georg Leber
Georg Leber

Reputation: 3580

I don't know any direct solution for this problem. You can load the URL to the properties file and then load the filename from that file:

ClassLoader loader = YourClass.class.getClassLoader(); 
URL resourceURL =loader.getResource("check.properties");
String fileToLoad = resourceURL.getPath() + <fileNameFromPropertyFile>;

Upvotes: 2

cloudhead
cloudhead

Reputation: 15353

I'm pretty sure it just defaults to the current directory, if not you can do

fileLocation="./fileName.txt"

Upvotes: 3

Michael Borgwardt
Michael Borgwardt

Reputation: 346516

No. Properties files do not have any builtin macro facilities. You can programmatically get the currect directory of the user running the Java app through the user.dir system property.

Upvotes: 8

Related Questions