I am trying to read from the file on the server side:

FileReader fr = new FileReader("text.txt"); 

The text.txt file is in the same folder as html (in the root of the war folder). When deploying to Tomcat, I get "File not found". Tell me, what path do I need to specify?

  • Show the structure, please - Chubatiy
  • With this use, it searches for the file from the launch point, i.e. from java ( java.exe ) location - Temka is also
  • The method of "throwing a file" has determined that it finds the file at the address: C: \ Program Files \ Apache Software Foundation \ Tomcat 8.0 - Zoran

1 answer 1

If you want to read files from the root of a web project (war), you need to use ServletContext # getResourceAsStream . You can get acquainted with other options for reading the link