How can I read a text file from a JSP page?

Mauricio Giraldo

This is some simple code I wrote to read a file and then write it in a different place in the same server:

<%@page <%@page language="java" import="*"%>
// Remember to declare the path correctly:
// Windows: path_to_fileFile.txt
// Unix: path_to_file/file.txt
// First: Read the file
FileInputStream data = new FileInputStream("path/file.txt");
BufferedInputStream file = new BufferedInputStream(data);
// Second: Write the file line by line
OutputStream out = new FileOutputStream("path/file2.txt");
int c = -1;
while((c = != -1) {
// Close and flush everything

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact