解决下载图片打不开的问题

String fileName=request.getParameter("fileName");  //图片的链接

//直接通过URL去读取图片
URL url=new URL(fileName);
URLConnection conn= url.openConnection();
InputStream stream=conn.getInputStream();
//获取image
BufferedImage image=ImageIO.read(stream);
ImageIO.write(image,"JPEG",response.getOutputStream());

response.addHeader("Content-Disposition", "attachment;filename=" + "图片名字");
//以流的形式输出
response.setContentType("application/octet-stream"); 

 

你可能感兴趣的:(下载)