How to access a text file from my war

How to find out which file link to use to get the file from my WAR.

WAR structure:

WAR
CSI
  - Model
  - Website Build
  WebContent
      META-INF
      WEB-INF
         LIB

The JSPs are under WebContent, I put the config.txt file in the WebContent folder and tried to get to it using

BufferedReader in = new BufferedReader (new FileReader ("WebContent / config.txt"));

But that does not work. Does anyone know which link I need to pass or how I can figure it out.

+5
source share
4

WebContent , .

+2

- , . - :

// In a Servlet
ServletContext sc = getServletContext();
BufferedReader in = 
    new BufferedReader(new FileReader(sc.getRealPath("WebContent/config.txt"));

, .

+1

:

InputStream input = getClass (). getClassLoader (). getResourceAsStream ("your / path / input / here");

-1
source

All Articles