简体   繁体   中英

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?

您可以将config.properties放入其中一个包中,然后定义相对属性文件的路径。

 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.

希望这会有所帮助: 添加属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM