How to add properties file into Java project?
I am u开发者_高级运维sing .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?
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");
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.
Hope this will help: Adding properties
精彩评论