Reputation: 5408
I am using a configuration (.ini) file with my java app. At the moment I am specifically calling the location of the dll like this.
Properties p = new Properties();
p.load(new FileInputStream("C:\\myconfigfile.ini");
I would like to have it so the user does not have to put it into a certain directory before the program operates.
Is there a way to implement this or is this just the best practice to go with.
Upvotes: 0
Views: 2303
Reputation: 7215
You should put your ini in a resources folder and load them as resources. Here's an excellent tutorial to get you started.
Upvotes: 1
Reputation: 14549
Have a look at Apache Commons Configuration. It is solving many issues around configuration files. It also supports having individual configs for each user what is imho very important for development in a team.
Upvotes: 1
Reputation: 308753
Put it in the CLASSPATH and load resource as stream using the class loader. That'll always work, even for web apps in WAR files or JARs.
Upvotes: 2
Reputation: 82559
make an ini folder in your root directory, and put it in there. Then when you start your program, it's all relative to where you start from.
Properties p = new Properties();
p.load(new FileInputStream(".\\ini\\myconfigfile.ini");
Upvotes: 1