读取Linux上图片


/**
     * 读取图片
     * @param path
     * @param response
     * @throws Exception
     */
    public static void showImg(String path,HttpServletResponse response) throws Exception{
        File file = new File(path);
        if (file.exists()) {
            FileInputStream fileIs= new FileInputStream(path);
            int i=fileIs.available(); //得到文件大小
            byte data[]=new byte[i];
            fileIs.read(data); //读数据
            //JSP禁止图片缓存
            response.setHeader( "Pragma", "no-cache" );
            response.addHeader( "Cache-Control", "must-revalidate" );
            response.addHeader( "Cache-Control", "no-cache" );
            response.addHeader( "Cache-Control", "no-store" );
            response.setDateHeader("Expires", 0);

            response.setHeader("Content-type", "image/png");
            OutputStream outStream=response.getOutputStream(); //得到向客户端输出二进制数据的对象
            outStream.write(data); //输出数据
            outStream.flush();
            outStream.close();
            fileIs.close();
        }

    }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM