【发布时间】:2020-04-15 14:20:29
【问题描述】:
我正在尝试将 zip 文件夹解压缩到文件夹,它可以工作并且它解压缩了一些文件夹,但是当它使用 index.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
我的解压缩功能,它可以工作,但对于 index.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();
}
}
【问题讨论】: