首页 > 解决方案 > 通过 NodeJS Express 发送 epub 文件

问题描述

我正在尝试将一个 zip 文件从 nodeJs 发送到 android,我使用以下方法在 android 中解压缩它:

public void unzip(String zipFile, String location) throws IOException {
    try {
        File f = new File(location);
        if (!f.isDirectory()) {
            f.mkdirs();
        }
        ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile));
        try {
            ZipEntry ze = null;
            while ((ze = zin.getNextEntry()) != null) {
                String path = location + File.separator + ze.getName();
                System.out.println(path);
                if (ze.isDirectory()) {
                    File unzipFile = new File(path);
                    if (!unzipFile.isDirectory()) {
                        unzipFile.mkdirs();
                    }
                } else {
                    FileOutputStream fout = new FileOutputStream(path, false);

                    try {
                        for (int c = zin.read(); c != -1; c = zin.read()) {
                            fout.write(c);
                        }
                        zin.closeEntry();
                    } finally {
                        fout.close();
                    }
                }
            }
        } finally {
            zin.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG, "Unzip exception", e);
    }
}

它给了我一个例外:

E/EXCEPTION: Unzip exception
java.io.EOFException: Unexpected end of ZLIB input stream

zip 文件包含 .opf、.ncx 和 .xml 文件。谁能帮忙

标签: androidnode.jsunzip

解决方案


推荐阅读