我已经在这个网站上阅读了很多关于我的问题的帖子,我的代码基于其中一些 . 我目前的问题是解压缩ePub导致只有使用LogCat提取的mimetype文件在我理解的创建文件夹时出错 .
以下是我用来解压缩任何zip文件,我从Problem when Unzipping得到它:
/**
* @author jon
*/
public class Decompress {
private String _zipFile;
private String _location;
ZipEntry ze = null;
public Decompress(String zipFile, String location) {
_zipFile = zipFile;
_location = location;
_dirChecker("");
}
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if (ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location
+ ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch (Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
Log.d("Decompress", f.getAbsolutePath().toString());
if (!f.isDirectory()) {
f.mkdirs();
}
}
}
我提到过的其他文章:Unzip a zipped file on sd card in Android application Why my decompress class don't make directories? Uzip folders recursively -android Render epub files in android Android EPUBLIB read/load content
这是我在mimetype文件后面的第二个文件(/文件夹)上收到的LogCat错误 .
03-24 10:38:13.991: E/Decompress(23190): java.io.FileNotFoundException: /storage/emulated/0/unzipped/yamani/CDS-suggestions.docx: open failed: ENOENT (No such file or directory)
我目前正在使用常规zip文件来测试我的代码 .
谢谢您的帮助 .
1 回答
能够通过使用此站点上找到的另一个片段来解决我的问题 .
资源: