I save the settings of my application in a properties file that I use in Ant and in a Java application. This may not be a good mark, but I find it very convenient to avoid duplication. The file contains variables such as:
usefulstuff.dir = ${user.home}/usefulstuff
So that other people can run the program on * nix systems, provided that they have a folder of useful information in their home directory.
Now the exciting thing is that this properties file works fine in Ant (the variable gets permission /home/username
), and when I load the same file directly into a Java application, I get a line containing ${user.home}/usefulstuff
, which not very helpful.
I load the details with this code in Ant:
<loadproperties srcFile="myProps.properties"/>
And in a Java application:
FileInputStream ins = new FileInputStream(propFilePath); myProps.load(ins); ins.close();
Did I miss something? Perhaps there is a better way to load properties in a Java application than load()
?
source share