Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

cant append write to file

843840Feb 26 2002 — edited Feb 26 2002
Howdo,
this servlet writes a new file, but when i rerun the servlet from the url unchached clientside, it does not write again. But if I call the same servlet with a different name. The first time it appends the data to the end of the file.
If i rerun it, it does nothing again?
anyone know why..

the FileWriter(string,true) should append to the file, but doesnt seem to work twice. is io stream open or something like that?

appreciate the help..
code follows.. thanks..

====

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWWWl extends HttpServlet {

String key = "try it";

public void init()
{
key = "1nd change";
String str = "zakju: \n";
try
{
key = "2nd change";
FileWriter logFile = new FileWriter("/sites/dir/zello3.html", true);

logFile.write(str);
logFile.close();
}
catch(Exception e){
key = "didnt work";
}
}

public void doGet(HttpServletRequest request,
HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n" +
"<HTML>\n" +
"<HEAD><TITLE>x2</TITLE></HEAD>\n" +
"<BODY>\n" +
"<H1>new day..</H1>\n<p>");
out.println(key);
out.println("</BODY></HTML>");


}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2002
Added on Feb 26 2002
1 comment
75 views