在哪里放置属性文件?

CSL*_*ner 9 java myeclipse properties

我尝试读取.properties文件并具有以下代码:

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");
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但它一直说文件没找到.

属性的内容是

pwd=passw0rd
Run Code Online (Sandbox Code Playgroud)

谁知道如何解决这个问题?

Jig*_*shi 19

它应该在classpath中,将它放到你的根源包中,如果它的maven项目把它放到src/main/resources目录中