日期:2014-05-18  浏览次数:20647 次

struts2 文件下载后怎么删除
网上搜了好久,基本上都是这个下载方式,
点击按钮,执行createCsv方法,生成临时文件,return “csv” ,根据@Results配置,调用downloadFile方法,下载到本机,问题在于,临时文件删不掉,请高手帮忙!(新人,分不多,见谅)
如下

@Results({ @Result(name = "csv", type = "stream", params = { "contentType", "text/plain", "contentDisposition",
"attachment;fileName=\"${fileName}\"", "inputName", "downloadFile", "bufferSize", "1024" }), })
public class Kaigaigw060Action extends KaigaiActionSupport implements ServletRequestAware {

public String createCsv() throws Exception {
csv文件生成代码。。。省略
return "csv";
}

public InputStream getDownloadFile() throws Exception {
String path = XXXXXXX;
FileInputStream stream = new FileInputStream(path);
File csvFile = new File(path);
if (csvFile.exists()) {
csvFile.delete();
}

return stream;

}


}

------解决方案--------------------
楼主的path是动态的呢,还是静态的?可以打断点看看,是否有path对应的文件,有没有其他程序在读写文件,在你删除时,如果有其他程序在读写文件,那就删不掉了。