亲测有效 公司项目中出现这个问题,发布一下,希望能帮到大家。
还对IE浏览器下载文件失败、出错进行了修复,保证中文文件名的正确显示,以及文件在IE下正确下载。
public InputStream getFileInputStream(String urlString) {
InputStream is = null;
try {
// 构造URL
URL url = new URL(urlString);
// 打开连接
URLConnection con = url.openConnection();
// 输入流
is = con.getInputStream();
} catch (Exception e) {
e.printStackTrace();
}
return is;
}
@RequestMapping(value = "/download",method = RequestMethod.POST)
public ResponseEntity<byte[]> download(String url, String fileName) throws IOException {//前端页面传过来的
log.info("url->" + url + ",fileName->" + fileName);
HttpHeaders headers