| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.goafanti.common.utils;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import javax.servlet.http.HttpServletResponse;
- public class PictureUtils {
- /**
- * 输出图片流
- * @param os
- * @param path
- * @throws IOException
- */
- public static void outputImage(HttpServletResponse response , String path) throws IOException{
- response.setHeader("Pragma", "No-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setDateHeader("Expires", 0);
- response.setContentType("image/jpg");
-
- OutputStream out = response.getOutputStream();
-
- File file = new File(path);
- FileInputStream fis;
- fis = new FileInputStream(file);
-
- long size = file.length();
- byte[] temp = new byte[(int) size];
- fis.read(temp, 0, (int) size);
- fis.close();
- byte[] data = temp;
-
- out.write(data);
- out.flush();
- out.close();
- }
- }
|