//下载附件
@RequestMapping("downCoordinatoinAttach")
public void downCoordinatoinAttach(HttpServletRequest request,HttpServletResponse response){
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
request.setCharacterEncoding("UTF-8");
String attachUrl = request.getParameter("attachUrl");
String fileName = "";
if(attachUrl != null && attachUrl.indexOf("/")>0){
fileName = attachUrl.substring(attachUrl.lastIndexOf("/")+1);
}else{
fileName = attachUrl.substring(attachUrl.lastIndexOf("\\")+1);
}
long fileLength = new File(attachUrl).length();
response.setContentType("application/x-msdownload;");
response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(fileLength));
bis = new BufferedInputStream(new FileInputStream(attachUrl));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null)
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
if (bos != null)
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}