Where to put a properties file?

CSLearner picture CSLearner · May 29, 2013 · Viewed 24.9k times · Source

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?

Answer

jmj picture jmj · May 29, 2013

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