java生成zip压缩文件

java生成zip压缩文件

public static void main(String[] args) {
    
    
		//创建父级目录 用于存放分区(分区中存放多个分类)
        String fatherPath = "D:\\qrCodeTest\\";
        File fatherFile = new File(fatherPath);
        try {
    
    
            if (!fatherFile.exists()) {
    
    
                fatherFile.mkdir();
            } else {
    
    
                fatherFile.delete();
                fatherFile.mkdir();
            }
        } catch (Exception e) {
    
    
            e.printStackTrace();
        }

        //创建list 存放图片
        List<File> fileList = new ArrayList<>();
        fileList.add(new File("D:\\qrCodeTest\\10000001.png"));
        fileList.add(new File("D:\\qrCodeTest\\10000002.png"));

        //遍历存储图片地址
        File zipFile = new File(fatherPath);
        // 调用压缩方法
        ZipMultiFileUtil.zipFiles(fileList.stream().toArray(File[]::new), zipFile);

        //将项目名称的文件夹 压缩为zip
        String fileDir ="D:\\";
        ZipMultiFileUtil.fileToZip(fatherPath, "", fileDir + "ces.zip");

	}

猜你喜欢

转载自blog.csdn.net/qq_16843563/article/details/127277266
今日推荐