String fileBase64Str = imagOneObject.getString("fileBase64Str"); byte[] base64bytes = new BASE64Decoder().decodeBuffer(fileBase64Str); File outputfile = new File("test.jpg"); ByteArrayInputStream bais = new ByteArrayInputStream(base64bytes); BufferedImage bi1 =ImageIO.read(bais); ImageIO.write(bi1, "jpg", outputfile);//不管输出什么格式图片,此处不需改动 main1(outputfile);
public static void main1(File file) { FileInputStream fis = null; ZipOutputStream zos = null; try { fis = new FileInputStream(file); zos = new ZipOutputStream(new FileOutputStream("e:/my.zip")); System.out.println(file.getName()); // 创建压缩文件中的条目 ZipEntry entry = new ZipEntry(file.getName()); // 将创建好的条目加入到压缩文件中 zos.putNextEntry(entry); // 写入当前条目所对应的具体内容 byte[] buff = new byte[1024]; int len = 0; while ((len = fis.read(buff)) != -1) { zos.write(buff, 0, len); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { fis.close(); zos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }