Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp JSP Open File

Related Tutorials


 
 

Share on Google+Share on Google+

JSP Open File

Advertisement
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

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: February 3, 2009

Related Tutorials

Discuss: JSP Open File   View All Comments

Post your Comment


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