Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:unzip download file

Tags:

android

Hi have create from window 7 and put that in server.Now i am downloading the file from server into my SD card.but when i start to unzip it show the error,

 java.util.zip.ZipException: EOCD not found; not a Zip archive?

the code i have use for unzip is

private void unzipEntry(ZipFile zipfile, ZipEntry entry,
                String outputDir) throws IOException {


            if (entry.isDirectory()) {
                createDir(new File(outputDir, entry.getName()));
                return;
            }

            File outputFile = new File(outputDir, entry.getName());
            if (!outputFile.getParentFile().exists()) {
                createDir(outputFile.getParentFile());
            }

            log("Extracting: " + entry);
            BufferedInputStream inputStream = new BufferedInputStream(
                    zipfile.getInputStream(entry));
            BufferedOutputStream outputStream = new BufferedOutputStream(
                    new FileOutputStream(outputFile));

            try {
                IOUtils.copy(inputStream, outputStream);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                outputStream.close();
                inputStream.close();
            }
        }

But when i directly import the file into ddms it work file.

Can anyone know how to resolve the issue then please help me out.

Thank you.

like image 348
Sameer Z. Avatar asked Aug 13 '26 21:08

Sameer Z.


2 Answers

   FileInputStream fin = new FileInputStream(
                zipfile);
        ZipInputStream zin = new ZipInputStream(fin);
        ZipEntry ze = null;
        while ((ze = zin.getNextEntry()) != null) {

            FileOutputStream fout = new FileOutputStream(
                    unzippath
                            + ze.getName());
            for (int c = zin.read(); c != -1; c = zin.read()) {
                fout.write(c);
            }

            zin.closeEntry();
            fout.close();

        }
        zin.close();

Try this .. This will solve your problem i guess.

like image 76
Nemo Avatar answered Aug 15 '26 11:08

Nemo


Check the ZipInputStream example given in the doc here.

like image 27
Ronnie Avatar answered Aug 15 '26 13:08

Ronnie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!