Al,
Instead of
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
do
//true indicates append
PrintWriter pw = new PrintWriter(new
FileOutputStream(nameOfTextFile,true));
Try PrintStream object if above does not work with PrintWriter.
Regards,
Mayank
-----Original Message-----
From: Al Higgs [mailto:al.higgs@b...]
Sent: Tuesday, March 12, 2002 1:20 PM
To: Pro_JavaServer_Pages
Subject: [pro_jsp] Text file writing success, and failure!!!!
Hello,
I have finally got the writing to text file working through JSP, using the
following code.
<%
String str = "print me";
String nameOfTextFile = "C:\\Jakarta-
Tomcat\\webapps\\ROOT\\higgsa\\log.txt";
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.print(str);
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
%>
However, this will always overwrite any text already in the file. Is
there any way of preventing this??
Thanks in advance
Al Higgs