压缩文件重复了 暂时不知道原因

生成的csv文件16k,然后压缩后解压变成了20k,并且有部分重复。暂时不知道原因,也没报错信息。记录下来说不定哪天就知道了,嘻嘻~

在这里插入图片描述

压缩代码如下:

 /**
     * 将存放在sourceFilePath目录下的源文件,打包成fileName名称的zip文件,并存放到zipFilePath路径下
     * 
     * @param sourceFilePath
     * @param zipFilePath
     * @return
     */
    public static boolean fileToZip(String sourceFilePath, String zipFilePath) throws Exception {
        boolean flag = false;
        // 读取原文件
        File sourceFile = new File(sourceFilePath);
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        FileOutputStream fos = null;
        ZipOutputStream zos = null;
        if (!sourceFile.exists() || sourceFile.list().length < 1) {
            LinkedHashMap<String, Object> logMap = new LinkedHashMap<String, Object>();
            logMap.put("sourceFile is not exist", sourceFilePath);
            MeUtils.info("sourceFile status", logMap);
        } else {
            try {
                File zipFile = new File(zipFilePath);
                if (zipFile.exists()) {
                    zipFile.delete();
                    // 如果文件存在,则删除
                }
                File[] sourceFiles = sourceFile.listFiles();
                fos = new FileOutputStream(zipFile);
                zos = new ZipOutputStream(new BufferedOutputStream(fos));
                // 设置字符流缓冲区
                byte[] bufs = new byte[10240];
                for (int i = 0; i < sourceFiles.length; i++) {
                    String fileName = sourceFiles[i].getName();
                    fileName = new String(fileName.getBytes("GBK"), System.getProperty("sun.jnu.encoding"));
                    // 创建压缩文件
                    ZipEntry zipEntry = new ZipEntry(fileName);
                    zos.putNextEntry(zipEntry);
                    // 读取待压缩的文件并写进压缩包里
                    fis = new FileInputStream(sourceFiles[i]);
                    bis = new BufferedInputStream(fis, 10240);
                    while (bis.read(bufs) != -1) {
                        zos.write(bufs);
                    }
                }
                flag = true;
            } catch (Exception e) {
                MeUtils.error(e);
            } finally {
                // 关闭流
                try {
                    if (bis != null) {
                        bis.close();
                    }
                    if (zos != null) {
                        zos.close();
                    }
                } catch (Exception e) {
                    MeUtils.error(e);
                }
            }
        }
        return flag;
    }

日志:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值