/** * 讀取圖片 * @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(); } }