Reputation: 123
I am using .properties
file for my project and Netbeans 6.9.1 IDE. How can I add my properties file into the code?
String prop="c:\\Config.properties";
Properties Config= new Properties();
Config.load(new FileInputStream(prop));
f1=Config.getProperty("f1");
f2=Config.getProperty("f2");
How can I define my Build path instead of "c:\\Config.properties"
?
Is there any way to add this file directly to the project?
Upvotes: 3
Views: 4606
Reputation: 6810
You could put the config.properties into one of your packages and then define the path to your properties file relative.
ClassLoader.getResourceAsStream ("your/app/package/config.properties");
Upvotes: 4
Reputation: 1331
Niraj,
Do not use the hardcoded path for your properties file. Either get the file path from the project properties or using the build/runtime values.
Upvotes: 0