Home Jsp JSP Open File



JSP Open File
Posted on: February 3, 2009 at 12:00 AM
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:

Related Tags for JSP Open File:
cjspfiletextsedintwriteopencreatejstextoexteilitusepeinntjpenintosspatiseaandxtssrithndo


More Tutorials from this section

Ask Questions?    Discuss: JSP Open File   View All Comments

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.