解压缩文件夹在Android中给出FileNotFound Exception



我正在尝试将zip文件夹解压缩到文件夹,它可以工作并且解压缩了一些文件夹,但是当它需要索引时.html它给出了这样的错误,我想将文件解压缩到文件夹但是我遇到了错误,我该如何解决这个问题?

W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.kocsistem.pixageoneandroid/files/Contents/widgetContent/ab34f7fe018a45f0a43d3139d6986b84/index.html (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
W/System.err:     at java.io.FileOutputStream.open(FileOutputStream.java:308)
at java.io.FileOutputStream.<init>(FileOutputStream.java:238)
at java.io.FileOutputStream.<init>(FileOutputStream.java:180)
at com.kocsistem.pixageoneandroid.utils.Utils.unpackZip(Utils.java:454)
at 

我的解压缩功能,它可以工作,但对于索引.html它给出了上述错误

public static void unpackZip(String src, String dest, String folderName){
final int BUFFER_SIZE = 4096;
BufferedOutputStream bufferedOutputStream = null;
FileInputStream fileInputStream;
try {
fileInputStream = new FileInputStream(src);
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(fileInputStream));
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null){
String zipEntryName = zipEntry.getName();
String name = dest.substring(dest.lastIndexOf("/")-1);
File FileName = new File(dest);
if (!FileName.isDirectory()) {
try {
if (FileName.mkdir()) {
} else {
}
} catch (Exception e) {
e.printStackTrace();
}
}
File file = new File(dest+ "/" + folderName +"/" +zipEntryName);
if (file.exists()){
} else {
if(zipEntry.isDirectory()){
file.mkdirs();
}else{
byte buffer[] = new byte[BUFFER_SIZE];
FileOutputStream fileOutputStream = new FileOutputStream(file);
bufferedOutputStream = new BufferedOutputStream(fileOutputStream, BUFFER_SIZE);
int count;
while ((count = zipInputStream.read(buffer, 0, BUFFER_SIZE)) != -1) {
bufferedOutputStream.write(buffer, 0, count);
}
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
}
}
zipInputStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

build.gradle

zip4jimplementation 'com.github.joielechong:zip4jandroid:1.0.1'

allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}

法典

String source = destFilePath + "/" + fileNameList.get(i);
String target = destFilePath.getAbsolutePath();
try {
ZipFile zipFile = new ZipFile(source);
zipFile.extractAll(target);
} catch (ZipException e) {
e.printStackTrace();
}

尝试使用以下代码:

1.创建第一个压缩文件

File FPath = new File(folder.getAbsolutePath() + File.separator + folderName);
if (FPath.exists()) FPath.delete();
String mPath = folder.getAbsolutePath() + File.separator + folderName+ ".zip";

FileOutputStream fos = new FileOutputStream(mPath);
InputStream is = cn.getInputStream();
int bytesRead = 0;
byte[] buf = new byte[8096];
long total = 0;
int progress;
int count = i;
while ((bytesRead = is.read(buf)) != -1) {
total += bytesRead;
fos.write(buf, 0, bytesRead);
}
if (is != null) is.close();
if (fos != null) {
fos.flush();
fos.close();
}

2.创建文件时

unpackZip(folder.getAbsolutePath() + File.separator, folderName);

3.您的职能

private boolean unpackZip(String path, String folderName) {
InputStream is;
ZipInputStream zis;
try {
String filename;
is = new FileInputStream(path + folderName+ ".zip");
zis = new ZipInputStream(new BufferedInputStream(is));
ZipEntry ze;
byte[] buffer = new byte[1024];
int count;
File refolder = new File(path + folderName);
if (!refolder.exists())
refolder.mkdirs();

while ((ze = zis.getNextEntry()) != null) {
filename = ze.getName();
if (ze.isDirectory()) {
File fmd = new File(refolder.getAbsolutePath() + "/" + filename);
fmd.mkdirs();
continue;
}
FileOutputStream fout = new FileOutputStream(refolder.getAbsolutePath() + "/" + filename);
while ((count = zis.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
fout.close();
zis.closeEntry();
}
zis.close();
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
File mFF = new File(path + folderName+ ".zip");
mFF.delete();
}
return true;
}