Java解压Zip文件(Java unzip file)


    public String unzipSourceCsvZipFile(String[] unzipFolderArrInPath, String sourceCsvZipFilePath) throws Exception {
        String targetFolderRealPath = FilesUtil.createFolderPath(unzipFolderArrInPath);
        ZipFile zipFile = new ZipFile(sourceCsvZipFilePath);
        Enumeration entries = zipFile.entries();
        OutputStream fosUserCsv = null;
        InputStream fisZipCsv = null;
        try {
            for (; entries.hasMoreElements(); ) {
                ZipEntry entry = (ZipEntry) entries.nextElement();
                String zipEntryName = entry.getName();
                if (entry.isDirectory()) {
                    continue;
                } else if (!zipEntryName.contains(CSV_FILE_EXTENTION)) {
                    continue;
                }
                String sourceCsvPath = targetFolderRealPath + File.separator + zipEntryName;
                fosUserCsv = new FileOutputStream(sourceCsvPath);
                fisZipCsv = zipFile.getInputStream(entry);
                byte[] buf1 = new byte[1024];
                int len;
                while ((len = fisZipCsv.read(buf1)) > 0) {
                    fosUserCsv.write(buf1, 0, len);
                }
                fosUserCsv.close();
                fisZipCsv.close();
            }
            return targetFolderRealPath;
        } finally {
            if (fosUserCsv != null) {
                fosUserCsv.close();
            }
            if (fisZipCsv != null) {
                fisZipCsv.close();
            }
            zipFile.close();
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_38844636/article/details/80450681
今日推荐