1

I am trying to read json data from a file I have in my WebContent folder, not my WEB-INF folder. Everything works when I use an absolute file path, but if I use another method to get the file path, the Java FileReader cannot find the file.

I am using a Java FileReader.

I have also tried using the below code, but it doesn't work:
String JSON_FILE = request.getServletContext().getRealPath("users.json");

Also, when I type in: users.json , after the base url, I can see the json data.

Any ideas?

Rohit Gaikwad
  • 3,677
  • 3
  • 17
  • 40
  • Did you try with `getRealPath("/users.json");` Anw, `getResourceAsStream` are recommended. Please refer: http://stackoverflow.com/questions/12160639/what-does-servletcontext-getrealpath-mean-and-when-should-i-use-it – Manh Le Oct 19 '16 at 05:43
  • Yes, I have. I also tried getClass().getResource() – Weston Sazehn Oct 19 '16 at 14:16

0 Answers0