PictureUtils.java 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.goafanti.common.utils;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import javax.servlet.http.HttpServletResponse;
  7. public class PictureUtils {
  8. /**
  9. * 输出图片流
  10. * @param os
  11. * @param path
  12. * @throws IOException
  13. */
  14. public static void outputImage(HttpServletResponse response , String path) throws IOException{
  15. response.setHeader("Pragma", "No-cache");
  16. response.setHeader("Cache-Control", "no-cache");
  17. response.setDateHeader("Expires", 0);
  18. response.setContentType("image/jpg");
  19. OutputStream out = response.getOutputStream();
  20. File file = new File(path);
  21. FileInputStream fis;
  22. fis = new FileInputStream(file);
  23. long size = file.length();
  24. byte[] temp = new byte[(int) size];
  25. fis.read(temp, 0, (int) size);
  26. fis.close();
  27. byte[] data = temp;
  28. out.write(data);
  29. out.flush();
  30. out.close();
  31. }
  32. }