讀取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