我写了个
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后没有把文件数据写进去。请问这是为什么?
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后没有把文件数据写进去。请问这是为什么?
2.刷新一下bw流,在write方法后面。
所以 关闭 tomcat的时候就写入。