gpt4 book ai didi

java - 如何解压缩包含图像的 Zip 文件而不在 android 中删除任何图像?

转载 作者:太空狗 更新时间:2023-10-29 16:39:09 25 4
gpt4 key购买 nike

<分区>

我正在解压缩仅包含图像的 zip 文件,下面给出了我的代码。

public void unZipImages(String zipFile, String outputFolder) {

byte[] buffer = new byte[2048];

try {

// create output directory is not exists
File folder = new File(Environment.getExternalStorageDirectory()
+ "/final_unzip_data/" + AppConstants.ManufacturerCode
+ "/Catalog/" + ""); if (!folder.exists()) {
folder.mkdir(); }

// get the zip file content
ZipInputStream zis = new ZipInputStream(
new FileInputStream(zipFile)); // get the zipped file list entry ZipEntry ze = zis.getNextEntry();

while (ze != null) {

String fileName = ze.getName();
if (fileName.contains("\\")) {
fileName = fileName.replace("\\", "/");
}
File newFile = new File(outputFolder + File.separator
+ fileName);

System.out.println("file unzip : " + newFile.getAbsoluteFile());

new File(newFile.getParent()).mkdirs();

FileOutputStream fos = new FileOutputStream(newFile);

int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}

fos.close();
ze = zis.getNextEntry(); }

zis.closeEntry(); zis.close();

System.out.println("Done");

} catch (IOException ex) { ex.printStackTrace(); } }

但我不知道解压缩某些图像丢失的文件时发生了什么错误。我已经搜索了多种类型的解压缩代码,但没有任何效果。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com