解压文件夹在android中出现FileNotFound异常
我正在尝试解压文件夹到文件夹,它的工作,它解压了一些文件夹,但当它采取index.html它给出这样的错误,我想解压文件到文件夹,但我得到了一个错误,我该如何解决这个问题解压文件夹在android中出现FileNotFound异常,android,unzip,Android,Unzip,我正在尝试解压文件夹到文件夹,它的工作,它解压了一些文件夹,但当它采取index.html它给出这样的错误,我想解压文件到文件夹,但我得到了一个错误,我该如何解决这个问题 W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.kocsistem.pixageoneandroid/files/Contents/widgetContent/ab34f7fe018a45f0a43d3139d6
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
请尝试使用以下代码:
1.首先创建zip文件
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;
}
格雷德尔先生
zip4j实现'com.github.joielechong:zip4jandroid:1.0.1'
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
代码
if(!refolder.exists())if(!refolder.mkdirs()){Toast(…抱歉无法创建目录…);return;}
File fmd=new File(refolder.getAbsolutePath()+“/”+filename)代码>更好:文件fmd=新文件(重新文件夹,文件名)代码>is=newfileinputstream(path+folderName+“.zip”)代码>错误。应该是is=newfileinputstream(路径)代码>如您在原始post.ContextWrapper cw=newcontextwrapper(context)中所见;folder=cw.getDir(“Name”,Context.MODE\u PRIVATE)@blackapps抱歉,请立即检查谢谢,它可以正常工作,不会出现FileNotFound异常
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();
}