我正在使用通过谷歌找到的类来解压缩.zip文件.. .zip包含文件和文件夹.问题是FileOutputStream
throws
FileNotFoundException
..但是文件应该从.zip文件中获取,那么它以前是如何存在的呢?
这是我在以下代码中使用的代码AsyncTask
:
@Override
protected Boolean doInBackground(String... params) {
try {
String zipFile = Path + FileName;
FileInputStream fin = new FileInputStream(zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(Path
+ ze.getName()); // <-- crashes here
while ((length = zin.read(buffer)) > 0) {
fout.write(buffer, 0, length);
publishProgress(length);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} …
Run Code Online (Sandbox Code Playgroud)