import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
byte[] bytes = HttpRequest.get(getDownloadArchivesUrl())
.body(getDownLoadParam(requestId, requestCreator))
.execute().bodyBytes();
// 将压缩包字节数组包装成输入流对象
// 创建ZipInputStream对象
try (ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(bytes), Charset.forName("GBK"))) {
// 遍历压缩包中的每个文件
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
try {
// 获取文件名
String filename = entry.getName();
if (!entry.isDirectory()) {
//对文件进行业务处理
} else {
//对目录进行处理
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
// 关闭当前文件的ZipEntry
try {
zipInputStream.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
第三方接口返回ResponseEntity<byte[]>文件压缩包,解压处理过程
于 2023-10-27 17:43:41 首次发布