Reputation: 15
I want to open a .config
file outside of the .jar
file so that I can use its properties inside of the .jar
. How would I do this?
Upvotes: 0
Views: 164
Reputation: 1976
Use this.
String path = System.getProperty("user.dir")
path += "/config/myApp.properties"
Now you have the path of your properties file. You know what to do next
Upvotes: 0
Reputation: 24630
For clearance you will use a config file from the (executable) jar like this:
InputStream in = this.getClass.getResourceAsStream("config.properties");
Properties p = new Properties();
p.load(in);
that loads config.properties relative to the class of the current object.
For a config outside you propably use a file:
InputStream in = new FileInputStream(System.getProperty("user.dir")+"/"+"config.properties");
Properties p = new Properties();
p.load(in);
Upvotes: 1