0

ファイルを解凍するために次のコードを使用してい.fsdますが、例外が表示されています。

java.util.zip.ZipException: Central Directory Entry not found

私のコードは次のとおりです。

public void unzipFolder(String zipfile_name,String unzipfolder_name){
    System.out.println("zip file nme----"+zipfile_name);

    try {
        ZipFile zf = new ZipFile(zipfile_name);
        System.out.println("zip file size----"+zf.size());
        Enumeration< ? extends ZipEntry> zipEnum = zf.entries();
        String dir = unzipfolder_name;

        while( zipEnum.hasMoreElements() ) {
        ZipEntry item = (ZipEntry) zipEnum.nextElement();

        if (item.isDirectory()) {
        File newdir = new File(dir + File.separator + item.getName());
        newdir.mkdir();
        } else {
        String newfilePath = dir + File.separator + item.getName();
        File newFile = new File(newfilePath);
        if (!newFile.getParentFile().exists()) {
        newFile.getParentFile().mkdirs();
        }
        copyInputStream(zf.getInputStream(item),
                   new BufferedOutputStream(new FileOutputStream(newfilePath)));

        }
        }
        zf.close();
        } catch (Exception e) {
        e.printStackTrace();
        }
}


public static final void copyInputStream(InputStream in, OutputStream out) {
    byte[] buffer = new byte[1024];
    int len;
    try {
        while((len = in.read(buffer)) >= 0){
            out.write(buffer, 0, len);
        }
        in.close();
        out.close();
    } catch (IOException e) {
        System.err.println("Zip -> copyInputStream : "+e.getMessage()); 
    }
}

ここでzipfile_name=/mnt/sdcard/forside_bookshelf_download/P160225200007046510000718MASenC.fsd、そしてunzipfolder_name=/mnt/sdcard/

次の行で上記の例外を受け取りました。

ZipFile zf = new ZipFile(zipfile_name);

誰でも私を助けることができますか?

4

1 に答える 1

0

私はzip4jで一度その問題を抱えていました。zipfile内にメインフォルダーを追加し、他のすべてのコンテンツをそこに入れると解決しました。

于 2012-08-28T14:46:21.977 に答える