Share on Google+Share on Google+

JSP Open File

JSP Open File is used to create a file and write a text into the file.

JSP Open File


JSP Open File is used to create a file and write a text into the file.

Understand with Example

 The Tutorial illustrate an example from JSP Open File. To understand the example we create openFile.jsp that include a page import directive "" package. The package  provides for system input and output through data streams, serialization and the file system. For this, we have create a file 'Hello.txt' in the C:drive. The  class FileOutputStream opens an output stream in order to write the specified text of line using the class PrintStream. In case the exception occurred , the catch block handle the exception and print the 'Unable to write to file'.

Here is the code of openFile.jsp

<%@ page import="*"%>
FileOutputStream out; 
out = new FileOutputStream("C://Hello.txt");
new PrintStream(out).println ("All glitters are not gold");
catch (IOException e){
out.println ("Unable to write to file");

When you run the above jsp code, the line of text, you have specified, will be written into the file Hello.txt.

Download Source Code:


Posted on: February 3, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JSP Open File   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image