首页 > 其他 > 详细

IO流读取图片

时间:2020-07-23 21:43:43      阅读:82      评论:0      收藏:0      [点我收藏+]

/**
*  
* @param imgName
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/IoReadImage/{imgName}", method = RequestMethod.GET)
public String IoReadImage(@PathVariable String imgName, HttpServletRequest request, HttpServletResponse response)
throws IOException
{
ServletOutputStream out = null;
FileInputStream ips = null;
try
{
//获取图片存放路径 
String imgPath = "C:\\Users\\booway\\Desktop\\" + imgName + ".png";
ips = new FileInputStream(new File(imgPath));
response.setContentType("multipart/form-data");
out = response.getOutputStream();
//读取文件流 
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = ips.read(buffer)) != -1)
{
out.write(buffer, 0, len);
}
out.flush();
} catch (Exception e)
{
e.printStackTrace();
} finally
{
out.close();
ips.close();
}
return null;
}

IO流读取图片

原文:https://www.cnblogs.com/closeIt/p/13367323.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!