标签:app com read let 方式 tps etc 输出流 highlight
前端请求路径:
<img src="<%=basePath%>commericalPart/readPartImage">
后台:
/**
* 读取图片
*/
@RequestMapping("/readPartImage")
@ResponseBody
public void readPartImage(HttpServletRequest request, HttpServletResponse response)throws Exception{
String path = request.getParameter("url");
File file = new File("E:/lazyli/image/part/本田/车身/1230474 防飞溅-17.jpg");
InputStream is = new FileInputStream(file);
byte[] bytes = new byte[is.available()];
is.read(bytes);
is.close();
//ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = response.getOutputStream();
/*int ch = 0;
while (-1 != (ch = is.read())){
os.write(bytes,0,ch);
}*/
response.setContentType("image/*");
os.write(bytes);
os.close();
}
第二种方式
/**
* 读取图片
*/
@RequestMapping("/readPartImage")
@ResponseBody
public void readPartImage(HttpServletRequest request, HttpServletResponse response)throws Exception{
String path = request.getParameter("url");
File file = new File("E:/lazyli/image/part/本田/车身/1230474 防飞溅-17.jpg");
InputStream is = new FileInputStream(file);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = response.getOutputStream();
int ch = 0;
while (-1 != (ch = is.read())){
baos.write(ch);
}
os.write(baos.toByteArray());
is.close();
baos.close();
os.close();
}
标签:app com read let 方式 tps etc 输出流 highlight
原文地址:https://www.cnblogs.com/lazyli/p/11739245.html