importjava.io.*;importjava.io.IOException;importjavax.servlet.ServletConfig;importjavax.servlet.ServletException;importjavax.servlet.http.*;publicclassTestLiftCycleServle...
import java.io.*;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class TestLiftCycleServlet extends HttpServlet {
@Override
public void destroy() {
System.out.println("destroy");
}
@Override
public void init(ServletConfig config) throws ServletException {
System.out.println("init");
}
public TestLiftCycleServlet() {
System.out.println("constructor!");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("doGet");
}
}
就是把system.out.println()的内容输出到文件里去,我想用java的方法实现,不是想记录日志,能不能写具体一点,File file =null;
PrintWriter pw = null;
try{
file = new File("c:\\6.txt");
pw = new PrintWriter(file);
pw.println("destroy");
} catch (Exception e ){
e.printStackTrace();
}
pw.close();
这个为什么不行?
zwxlovellm的方法不行
展开