1、首先后台接收后,多文件名进行再编码
filePath = new String(filePath.getBytes(),"utf-8");//有没有这句话
2、注意设置浏览器,很重要
//浏览器设置
String userAgent = request.getHeader("User-Agent");
if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
//IE浏览器处理
fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
} else {
// 非IE浏览器的处理:
fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");
}
// 设置文件头:最后一个参数是设置下载文件名
response.setHeader("Content-Disposition", "attachment;fileName="+fileName);
// 设置文件ContentType类型,这样设置,会自动判断下载文件类型
response.setContentType("application/octet-stream;charset=utf-8");
//流对拷
OutputStream os = response.getOutputStream();
int len = 0;
byte[] b = new byte[1024];
while ((len = is.read(b)) > 0) {
os.write(b, 0, len);
}
os.close();
is.close();