public static void downLoadFile(HttpServletRequest request,HttpServletResponse response,String fullPath) throws IOException {
OutputStream outp = response.getOutputStream();
File file = new File(fullPath);
if (file.exists()) {
response.setContentType("application/x-msdownload; charset=utf-8");
String agent = (String)request.getHeader("USER-AGENT");
if (agent != null &&agent.toLowerCase().indexOf("firefox") > 0) {
response.setHeader("Content-Disposition", "attachment; filename=" + new String(filename.getBytes("UTF-8"), "ISO8859-1"));
}else {
response.setHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode(filename, "UTF-8"));
}
FileInputStream in = null;
try {
outp = response.getOutputStream();
in = new FileInputStream(fullPath);
byte[] b = new byte[1024];
int i = 0;
while ((i = in.read(b)) > 0) {
outp.write(b, 0, i);
}
outp.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
in.close();
in = null;
}
if (outp != null) {
outp.close();
outp = null;
response.flushBuffer();
}
}
} else {
outp.write("文件不存在!".getBytes("utf-8"));
}
}