[英]How to convert a byte array of zip files to ZipFile with type as ZipFile?
byte[] zipBytes = fileService.get("RINV_242_20220629-150309.ZIP");
ZipFile zipFile = new ZipFile(zipBytes);
I'm not sure if my code will give you a better understanding of my problem.我不确定我的代码是否能让您更好地理解我的问题。 But I want to convert byte array to zipFile, what do I need to do?
但是我想将字节数组转换为zipFile,我需要做什么?
You can't use java.util.zip.ZipFile
without saving it to a file on a file system.如果不将
java.util.zip.ZipFile
保存到文件系统上的文件中,则无法使用它。 If you want to get it from a byte[]
without saving, you need to use java.util.zip.ZipInputStream
, and wrap the byte[]
in a ByteArrayInputStream
.如果您想从
byte[]
获取它而不保存,则需要使用java.util.zip.ZipInputStream
,并将byte[]
包装在ByteArrayInputStream
中。
Something like:就像是:
try (ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipBytes))) {
// ...
}
The thing you lose compared to ZipFile
is that you can't enumerate the files or request individual files.与
ZipFile
相比,您失去的东西是您无法枚举文件或请求单个文件。 Instead, you have to iterate over zip entries with getNextEntry()
.相反,您必须使用
getNextEntry()
遍历 zip 条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.