Maison > Article > interface Web > java 返回图片到页面_html/css_WEB-ITnose
@RequestMapping(value = "/image/get")
public void getImage(HttpServletRequest request,HttpServletResponse response) {
FileInputStream fis = null;
response.setContentType("image/gif");
try {
OutputStream out = response.getOutputStream();
File file = new File("D:"+File.separator+"timg.jpg");
fis = new FileInputStream(file);
byte[] b = new byte[fis.available()];
fis.read(b);
out.write(b);
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}