@RequestMapping("/down")
@ResponseBody
public void down(HttpServletRequest request, HttpServletResponse response) throws Exception {
//将该路径图片下载
String path = "D:/img.png";
//获取文件
File file = new File(path);
//将图片读成二进制流
FileImageInputStream fs = new FileImageInputStream (file);
int streamLength = (int)fs.length();
byte[] image = new byte[streamLength ];
fs.read(image,0,streamLength );
fs.close();
response.setHeader("Content-Type","application/octet-stream");
//filename下载时的违建名称
response.setHeader("Content-Disposition","attachment;filename=5g.png");
response.getOutputStream().write(image);
response.getOutputStream().flush();
response.getOutputStream().close();
}
浏览器下载img
最新推荐文章于 2024-04-16 09:52:17 发布