Where to put a properties file?

25,999

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

Share:
25,999
Admin
Author by

Admin

Updated on June 24, 2020

Comments

  • Admin
    Admin about 4 years

    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?