日期:2014-05-17 浏览次数:20773 次
/**
* 下载文件
* @param filePath 文件路径(物理路径)
* @param fileName 源文件名称
*/
public void downLoadFile(String filePath, String fileName) {
File file = new File(filePath);
if (!file.exists()
------解决方案--------------------
file.isDirectory()) {
return;
}
InputStream input =null;
OutputStream output = null;
try {
input = new FileInputStream(file);
output = response.getOutputStream();
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
byte[] buffer = new byte[1024];
int i = 0;
while ((i = input.read(buffer)) != -1) {
output.write(buffer, 0, i);
}
} catch (Exception e) {} finally {
try {
if(null !=output) {
output.flush();
output.close();
}
if(null !=input) {
input.close();
}
} catch (Exception e) {}
}
}