[JAVA] Read the file under WEB-INF when executing the Servlet

Premise

Implemented using java8 tomcat7 seasar2

Get files using Servlet context

Since there was a Util to get the Servlet in sastruts, use

ServletContext context = ServletContextUtil.getServletContext(); String path = context.getRealPath("WEB-INF/classes/xxx.txt"); File file = new File(path);

There may be few usage scenes, but a memorandum

Recommended Posts

Read the file under WEB-INF when executing the Servlet
Read the file under the classpath as a character string with spring
Change the Swagger-ui read file. (Using AWS/Docker)
Read the file line by line VS read at once
Reload every time the file under lib/is reloaded
[Java] Read the file in src / main / resources