@author Administrator
| 15 | * |
| 16 | */ |
| 17 | public class ImageUtil { |
| 18 | |
| 19 | // 读取本地图片获取输入流 |
| 20 | public static FileInputStream readImage(String path) throws IOException { |
| 21 | return new FileInputStream(new File(path)); |
| 22 | } |
| 23 | |
| 24 | // 读取表中图片获取输出流 |
| 25 | public static void readBin2Image(InputStream in, String targetPath) { |
| 26 | File file = new File(targetPath); |
| 27 | String path = targetPath.substring(0, targetPath.lastIndexOf("/")); |
| 28 | if (!file.exists()) { |
| 29 | new File(path).mkdir(); |
| 30 | } |
| 31 | FileOutputStream fos = null; |
| 32 | try { |
| 33 | fos = new FileOutputStream(file); |
| 34 | int len = 0; |
| 35 | byte[] buf = new byte[1024]; |
| 36 | while ((len = in.read(buf)) != -1) { |
| 37 | fos.write(buf, 0, len); |
| 38 | } |
| 39 | fos.flush(); |
| 40 | } catch (Exception e) { |
| 41 | e.printStackTrace(); |
| 42 | } finally { |
| 43 | if (null != fos) { |
| 44 | try { |
| 45 | fos.close(); |
| 46 | } catch (IOException e) { |
| 47 | e.printStackTrace(); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
nothing calls this directly
no outgoing calls
no test coverage detected