我有解压缩代码,如果zip文件具有1.90 GB txt文件初始化,则能够解压缩。 但是当zip文件包含2GB文本文件时无法解压缩。
这里代码: / ** *方法解压缩附近2GB的zip文件不超过这个。 *提供zip文件路径和输出文件夹所有解压缩文件 *将被复制到输出文件夹 * /
public void unZipIt(String zipFile, String outputFolder) {
// create output directory is not exists
File folder = new File(outputFolder);
if (!folder.exists()) {
folder.mkdir();
}
//extract zip if already present skip file from extraction
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(
zipFile));) {
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
File newFile = new File(outputFolder + File.separator
+ fileName);
if (!newFile.exists()) {
new File(newFile.getParent()).mkdirs();
ze = writeExtractedFile(zis, newFile);
AutoLog.getLogger().info("File extracted: "+fileName);
}
else
{
AutoLog.getLogger().info("File aready present in directory so skip file:"+fileName);
ze=zis.getNextEntry();
}
}
zis.closeEntry();
} catch (IOException e) {
Assert.fail("Fail to unzip zip file", e);
}
}
/**
* helper method for zip extract
* new created file in output folder this method will write the same data
* to this files.
*/
private ZipEntry writeExtractedFile(ZipInputStream zis,
File newFile) {
byte[] buffer = new byte[10];
ZipEntry ze = null;
try (FileOutputStream fos = new FileOutputStream(newFile)) {
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
ze = zis.getNextEntry();
return ze;
} catch (Exception e) {
Assert.fail("Fail to write extracted file", e);
}
return ze;
}