读取本地照片 以流的形式进行显示
获取到前端传来的文件名称,到相应的文件中去读取,通过流的形式写到响应体中。
/**
* 显示图片
* getFeedBackPicture.do?picName=
* @return
*/
@RequestMapping(value="/viewPhoto/{photopath}")
public void getFeedBackPicture(HttpServletResponse response,@PathVariable("photopath")String photopath) throws Exception{
String realPath="D:/demo/download/"+photopath;
FileInputStream inputStream = new FileInputStream(realPath);
int i = inputStream.available();
//byte数组用于存放图片字节数据
byte[] buff = new byte[i];
inputStream.read(buff);
//记得关闭输入流
inputStream.close();
//设置发送到客户端的响应内容类型
response.setContentType("image/*");
OutputStream out = response.getOutputStream();
out.write(buff);
//关闭响应输出流
out.close();
}