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 "java.io" package. The java.io 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="java.io.*"%>
<%
FileOutputStream out; 
try{
out = new FileOutputStream("C://Hello.txt");
new PrintStream(out).println ("All glitters are not gold");
out.close(); 
}
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:

Advertisements

Ads

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

JSP Open File

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

Advertisements

Ads
 

Discuss: JSP Open File   View All Comments

Post your Comment


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

Ads

 

Ads