关于struts2的文件上传下载的问题

我用struts2做了一个功能,后台生成一个文件,页面上返回一个该文件的连接,用户可以下载,现在的问题是,怎样能够在用户下载后系统自动删除这个文件,避免服务器上的临时文件过多
[b]问题补充:[/b]
能不能给点代码阿?仁兄
[b]问题补充:[/b]
我这里就是这样弄的,还望仁兄指点一二

[url]http://www.blogjava.net/beansoft/archive/2008/03/03/183468.html[/url]

你采用上面文章中的下载方式,然后在下载的方法里面想办法调用删除文件的方法

不要通过连接的方式来下载文件.这样struts2都不知道你下载了没有
你可以通过struts2的流下载方式,当他把文件流读完后紧接着删除

用response从定向流的方式,让用户下载,写上删除语句
System.out.println("From "+fromPath);
System.out.println("To "+toPath);
CompressFolder cf=new CompressFolder();//压缩文件
cf.compressOneFolder(fromPath, toPath);
File file=new File(toPath+"excel.zip");//传到前台下载
String filenamedownload = file.toString();
String filenamedisplay = file.getName();
response.addHeader("Content-Disposition", "attachment;filename="+ filenamedisplay);
OutputStream output = null;
FileInputStream fis = null;

try {
output = response.getOutputStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while ((i = fis.read(b)) > 0) {
output.write(b, 0, i);
}
output.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
fis = null;
}
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
output = null;
}
}