zoukankan      html  css  js  c++  java
  • JAVA中解压压缩包到制定文件夹工具方法

    最近项目中看到一个别人写的解压压缩文件的方法,感觉不错,特此记录下来,方便与以后遇到类似问题。

     // 第一个参数就是需要解压的文件,第二个就是解压的目录
        public static boolean upZipFile(String zipFile, String folderPath) {
            ZipFile zfile = null;
            try {
                zfile = new ZipFile(zipFile);
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
            Enumeration zList = zfile.entries();
            ZipEntry ze = null;
            byte[] buf = new byte[1024];
            while (zList.hasMoreElements()) {
                ze = (ZipEntry) zList.nextElement();
                if (ze.isDirectory()) {
                    String dirstr = folderPath + ze.getName();
                    dirstr.trim();
                    File f = new File(dirstr);
                    f.mkdir();
                    continue;
                }
                OutputStream os = null;
                FileOutputStream fos = null;
                File realFile = getRealFileName(folderPath, ze.getName());
                try {
                    fos = new FileOutputStream(realFile);
                } catch (FileNotFoundException e) {
                    return false;
                }
                os = new BufferedOutputStream(fos);
                InputStream is = null;
                try {
                    is = new BufferedInputStream(zfile.getInputStream(ze));
                } catch (IOException e) {
                    return false;
                }
                int readLen = 0;
                // 进行一些内容复制操作
                try {
                    while ((readLen = is.read(buf, 0, 1024)) != -1) {
                        os.write(buf, 0, readLen);
                    }
                } catch (IOException e) {
                    return false;
                }
                try {
                    is.close();
                    os.close();
                } catch (IOException e) {
                    return false;
                }
            }
            try {
                zfile.close();
            } catch (IOException e) {
                return false;
            }
            return true;
        }
  • 相关阅读:
    大型web系统数据缓存设计
    配置AndroidStudio
    android-studio 安装gradle
    Gradle的简介与安装
    史上最详细的Android Studio系列教程四--Gradle基础
    Android SDK
    如何让猎头找到你
    android-volley-manager
    Android Studio导入Project的方法
    设置Android Studio启动时可选最近打开过的工程
  • 原文地址:https://www.cnblogs.com/zblwyj/p/11275137.html
Copyright © 2011-2022 走看看