Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Text file writing success, and failure!!!!


Message #1 by "Al Higgs" <al.higgs@b...> on Tue, 12 Mar 2002 13:20:14
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


  Return to Index