英文:
How do I extract data from a zip archive that is represented as byte []?
问题
以下是翻译好的部分:
如何从表示为 byte [] 的 zip 归档中提取数据?
public static byte[] extractSingleFile(byte[] zip) {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(zip);
final ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream);
final byte[] bytes = IOUtils.toByteArray(zipInputStream);
return bytes;
}
始终返回空的 byte []
如果我使用以下方式将 byte [] zip 写入磁盘文件:
final FileOutputStream fileOutputStream = new FileOutputStream(new File("somefile.zip"));
fileOutputStream.write(zip);
那么创建的 zip 归档会正常打开(即问题不在传递给方法的数组中)。
英文:
How do I extract data from a zip archive that is represented as byte []?
public static byte[] extractSingleFile(byte[] zip) {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(zip);
final ZipInputStream gzipInputStream = new ZipInputStream(byteArrayInputStream);
final byte[] bytes = IOUtils.toByteArray(gzipInputStream);
return bytes;
}
Always returns an empty byte []
If I write byte [] zip as a file to disk using
final FileOutputStream fileOutputStream = new FileOutputStream(new File("somefile.zip"));
fileOutputStream.write(zip);
Then the created zip archive is opened normally (i.e. the problem is not in the array passed to the method)
专注分享java语言的经验与见解,让所有开发者获益!
评论