我正在尝试使用以下代码从S3存储桶下载ZIP存档:
S3Object fullObject = client.getObject(bucketName, key);
S3ObjectInputStream stream = fullObject.getObjectContent();
FileOutputStream outputStream = new FileOutputStream(archiveName);
while ((count = stream.read(data)) != -1) {
outputStream.write(data, 0, count);
}
outputStream.close();
stream.close();
文件被下载,它与S3中放置的文件大小相同,唯一的问题是它已损坏。如果我输入unzip -t <archive_name.zip>
,我会收到以下错误:
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of PCxazGHgMmDedx8wNM16L.zip or
PCxazGHgMmDedx8wNM16L.zip.zip, and cannot find PCxazGHgMmDedx8wNM16L.zip.ZIP, period.
我尝试使用这样声明的ZipOutputStream
:
ZipOutputStream zipStream = new ZipOutputStream(new BufferedOutputStream(outputStream));
但它需要一个ZipEntry,它基本上是一个我无法看到的归档中的新文件/目录,因为我只有一个流。
我该如何解决这个问题?
谢天谢地。