我写了个
public void destroy() {
// TODO Auto-generated method stub
BufferedWriter bw=null;
     try {
FileWriter fw=new FileWriter("D:/times.txt");
bw=new BufferedWriter(fw);
bw.write(this.getServletContext().getAttribute("times").toString());

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
try {
bw.close();
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
}
}
关闭tomcat后没有把文件数据写进去。请问这是为什么?

解决方案 »

  1.   

    多次测试发现直接关闭tomcat的startup没有写入,用shutdown关闭服务器就写入了,请问这是什么问题?
      

  2.   

    1.FileWriter fw=new FileWriter("D:/times.txt");文件路径写错了,D:\\times.txt
    2.刷新一下bw流,在write方法后面。
      

  3.   

    D:/times.txt可以这么写也可以你那么写,直接关闭tomcat的startup没有写入,但是用shutdown关闭服务器就写入了,请问这是什么问题?
      

  4.   

    servlet被移除服务,调用destroy方法销毁
    所以  关闭 tomcat的时候就写入。
      

  5.   

    为什么直接点startup的红叉没有用呢?