John D
John D

Reputation: 123

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?

Upvotes: 3

Views: 4606

Answers (3)

user883769
user883769

Reputation: 18

Hope this will help: Adding properties

Upvotes: 0

flash
flash

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

Sathwick
Sathwick

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

Related Questions