0

I am trying to access a .properties file inside the web-inf folder in java, but I could not figure out how to do it.

If the file cannot be accessed, why is that?

Yet, I can access files from inside the package. The code for that is as follows:

Properties prop = new Properties();
        InputStream in = ReadPropertyFile.class.getResourceAsStream("temp.properties");
        prop.load(in);
        System.out.println(prop.getProperty("asd"));
        in.close();

So how to achieve this inside a java class?

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
sree
  • 535
  • 4
  • 12
  • 26

1 Answers1

2

I have tried using below code.

        Properties prop = new Properties();
        prop.load(new FileInputStream("./WebContent/WEB-INF/my.properties"));
        System.out.println(prop.getProperty("data"));

and it worked.

Vinayak Pingale
  • 1,315
  • 8
  • 19