`

读取图像文件

    博客分类:
  • Java
 
阅读更多
1. 将字节数组转换成图像文件

byte[] byteArray = 要处理的字节数组
InputStream in = new ByteArrayInputStream(byteArray);
                            BufferedImage img;
                            try {
                                img = ImageIO.read(in);
                               File outputfile = new File("C:\\Temp\\", "testimage.png");
                                ImageIO.write(img, "png", outputfile);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

2. 读取压缩文件

byte[] reportZip = 要处理的字节文件数组;

ZipInputStream zis = null;
zis = new ZipInputStream(new ByteArrayInputStream(reportZip));
ZipEntry ze = zis.getNextEntry();
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
                            int n;
                            while ((n = zis.read(buffer)) != -1) {
                                baos.write(buffer, 0, n);
                            }                           
// 可以将baos写入输入库,如果是图像,在mysql中需要将字段设置为blob格式
                            baos.flush();
                            baos.close();
zis.closeEntry();
zis.close();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics