• 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;
        }
  • 相关阅读:
    js当地天气调用
    js 3D旋转效果
    js 格林威治时间转正常格式并兼容ios
    vue中使用百度地图,悬浮窗搜索功能
    js 百度地图定位
    高德地图坐标与百度地图坐标相互转换
    js高德地图手机定位
    数据循环处理重组2
    数据循环处理重组1
    百度地图搜索框在弹框中不显示
  • 原文地址:https://www.cnblogs.com/zblwyj/p/11275137.html
Copyright © 2020-2023  润新知