Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add properties file into Java project?

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?

like image 217
John D Avatar asked Apr 17 '26 09:04

John D


1 Answers

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");
like image 104
flash Avatar answered Apr 18 '26 21:04

flash