public static boolean unZip(String zipDirectory, String storageDirectory,
            String fileName) {
        boolean result = false;
        String zipName = zipDirectory + fileName;
        String filePath = storageDirectory;
        ZipFile zipFile = null;
        BufferedInputStream bis = null;
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        try {
            zipFile = new ZipFile(zipName);
            Enumeration<? extends ZipEntry> emu = zipFile.entries();
            while (emu.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) emu.nextElement();
                if (entry.isDirectory()) {
                    new File(filePath + entry.getName()).mkdirs();
                    continue;
                }
                bis = new BufferedInputStream(zipFile.getInputStream(entry));
                File file = new File(filePath + entry.getName());
                File parent = file.getParentFile();
                if (parent != null && (!parent.exists())) {
                    parent.mkdirs();
                }
                fos = new FileOutputStream(file);
                bos = new BufferedOutputStream(fos, BUFFER);
                int count;
                byte data[] = new byte[BUFFER];
                while ((count = bis.read(data, 0, BUFFER)) != -1) {
                    bos.write(data, 0, count);
                }
                bos.flush();
            }
            result = true;
        }
        catch (Exception e) {
            e.printStackTrace();
            result = false;
        }
        finally {
            try {
                if (null != bos) {
                    bos.close();
                }
                if (null != bis) {
                    bis.close();
                }
                if (null != zipFile) {
                    zipFile.close();
                }
            }
            catch (IOException e) {
                e.printStackTrace();
                result = false;
            }
        }
        return result;
    }
原来写过的一个解压方法,可以正常解压。zipDirectory 是压缩文件路径
storageDirectory 是解压文件路径
fileName 是压缩文件名(xxx.zip)

解决方案 »

  1.   

    没有抛出异常错误,但是在ABC的文件夹下看不到解压的文件
      

  2.   

    你的解压的文件名最前面带.么?
    带.在linux系统默认是隐藏文件夹。
    在file explorer中是看不到的。
    在shell命令下可以用 ls -a看到。
      

  3.   

    权限有添加的,路径我弹出框看了下是mnt\sdcard\ABC\abc.zip,额
      

  4.   

    嗯。这种情况可以debug一下。
      

  5.   

    我用了下你写的那个方法,然后发觉while循环没有走进去,但是也没有报错,这个是因为没找到文件么?我自己的那个方法,好像在android上面有错
      

  6.   

    也许你的压缩方法是将所有文件直接压入zip。
    我这个方法是利用zipEntry进行的按文件夹进行压缩。可能跟你的压缩方式不一样。如果需要的话我可以把doZip发给你。
    下次回复记得点引用。要不我这里没有提示
      

  7.   


    呵呵, 最近也在搞这个东西
    LZ 可以借鉴一下如下博文 
    http://blog.csdn.net/spjhandsomeman/article/details/8140182希望有所帮助
      

  8.   

    想问下rar文件或其他文件解压怎么弄?谢谢!