Home >Web Front-end >HTML Tutorial >java returns images to page_html/css_WEB-ITnose

java returns images to page_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:48:011532browse

@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();
            }   
              }
        }
    }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn