导入压缩文件

    /**
     * 导入压缩文件
     *
     * @param file
     * @param charsetName
     * @param consumer
     */
    public static void importZipFile(MultipartFile file, String charsetName, ThrowExceptionBiConsumer<ZipInputStream, ZipEntry> consumer)
    {
        try (ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.forName(charsetName)))
        {
            while (true)
            {
                ZipEntry nextEntry = zipInputStream.getNextEntry();

                if (nextEntry == null)
                {
                    break;
                }

                consumer.accept(zipInputStream, nextEntry);
            }
        }
        catch (Exception e)
        {
            log.error(e.getMessage(), e);
            throw new BaseException(e.getMessage(), e);
        }
    }

  

posted @ 2022-09-16 17:16  这很周锐  阅读(36)  评论(0编辑  收藏  举报