How do I read text file in Servlet?

This example show you how to read a text file using a Servlet. Use ServletContext.getResourceAsStream() will enable you to read a file whether the web application is deployed in an exploded format or in a war file archive.

The file is just a regular text file. Below is an example of the configuration we are going to read.