by Dinesh Thakur Category: JSP Elements

In this Example we will discuss about how to read text file with the JSP objects. First we create a text file that contains strings in it. In the program we use input and output stream for execute the expression.


We put the text file in the WEB/INF folder where it will be fetched in the program we just give the reference of this folder. For storing the content of a file we also use the buffered reader function. readLine method also used to read the content of text file stored in WEB/INF folder.

<%@ page import="* "%>



     <title>&lt;ReadingTextFile&gt; In JSP</title>


    <body bgcolor="#E1EDF3">

    <h3 align="center"><br><%

    String fileName = "/WEB-INF/Reading.txt";

    InputStream instrm = application.getResourceAsStream(fileName);



          if(instrm == null)






                    BufferedReader bfrdr = new BufferedReader((new InputStreamReader(instrm)));

                   String cntnt;

                   while((cntnt= bfrdr.readLine())!= null)






            catch(IOException e1)







         Jsp readingTextFile Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.