dcsimg
How to create a text file on a server from a JSP page
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chandra_shekar
Posted On:   Friday, April 27, 2001 02:02 PM

Can anyone help me how to create a text file on a server (http://servername....), The file should be created if the one is not existing, otherwise it should overwrite the old one, if exists. I used the below code to create it, but I cannot see the file at server. I dont now whether the file is creating or not, when I used the URL http://servername.../Hello.txt, I am getting Error as Error 404--Not Found, From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1: the code was : --------------------------- <%@ page import="java.io.*" %> <% String str = "print me"; //always give the path from root. This way it almost always works. String nameOfTextFile = "Hello.txt";    More>>

Can anyone help me how to create a text file on a server (http://servername....), The file should be created if the one is not existing, otherwise it should overwrite the old one, if exists. I used the below code to create it, but I cannot see the file at server. I dont now whether the file is creating or not, when I used the URL http://servername.../Hello.txt, I am getting Error as Error 404--Not Found, From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:

the code was :
---------------------------
<%@ page import="java.io.*" %>
<%
String str = "print me";
//always give the path from root. This way it almost always works.
String nameOfTextFile = "Hello.txt";

try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(str);
//clean up
pw.close();
out.println("Created.....");
} catch(IOException e) {
out.println(e.getMessage());
}
%>
-----------------------

I would appreciate if anyone can help me to solve this problem.

thanks
Chandra

   <<Less
About | Sitemap | Contact