// 创建;临时文件
File zip = File.createTempFile("asdcasdcas", ".zip");
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip));
for (Document document : fileList) {
zos.putNextEntry(new ZipEntry(document.getDocumentName())); // 获取照片名字
zos.write(document.getContent()); // 获取byte[]型照片
zos.flush(); // 将这张照片存入到了zip
zos.closeEntry();
}
FileInputStream fis = new FileInputStream(zip);
// FileInputStream转byte[]
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
byte[] bt = bos.toByteArray();
zos.close();
fis.close();
bos.close();
zip.deleteOnExit(); // 删除临时文件