Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put a properties file?

I tried to read a .properties file and have code as following:

public final class Config  {
  static {
    Properties properties = new Properties();
    InputStream propertiesStream = Object.class.getResourceAsStream("config.properties");

    if (propertiesStream != null) {
      try {
        properties.load(propertiesStream);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      System.out.println("file not found");
    }
  }
}

but it keeps saying file not found.

The content of properties is

pwd=passw0rd

Anyone knows how to solve this problem?

like image 763
CSLearner Avatar asked May 29 '13 05:05

CSLearner


People also ask

Where should I put properties file Java?

properties file inside your resource folder of the java project. The extension we use for the properties file is . properties.

Where do I put config Properties?

The file must be present at /data/vcps/config/config. properties.

How do I add to properties file?

Right-click and select Add New Properties File. A new properties file will be added to your project. The new file will be selected and highlighted in the list.


1 Answers

It should be in classpath, put it to your root source package, if its a maven project put it to src/main/resources directory

like image 95
jmj Avatar answered Oct 05 '22 23:10

jmj