使用hutool实现压缩zip到输出流(包括空zip)
//将文件直接压缩至输出流 String[] fileNames = fileNameList.toArray(new String[0]); InputStream[] inputStreams = inputStreamList.toArray(new InputStream[0]); if (ArrayUtil.isNotEmpty(fileNames)) { //输出压缩文件到指定的输出流 ZipUtil.zip(outputStream, fileNames, inputStreams); } else { //输出空zip到指定的输出流 ZipOutputStream zipOutputStream = ZipUtil.getZipOutputStream(outputStream, CharsetUtil.defaultCharset()); ZipWriter zipWriter = new ZipWriter(zipOutputStream); zipWriter.close(); }