vc++中压缩文件--ZIP Util

这篇博客介绍了如何在VC++中利用ZIP Util库进行文件压缩。通过创建并添加数据到data.txt文件,然后将其压缩成Radar.zip,展示了使用zip.cpp和zip.h头文件的步骤。最后,压缩完成后,源文件data.txt被删除。
摘要由CSDN通过智能技术生成



用到的是zip util 的方法:

首先需要网上搜索下载 zip.cpp和zip.h两文件,然后添加到工程中!


下面是我做的一个实现压缩的小例子:


#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include "zip.h"


void CreateFiles();
int _tmain(int argc, _TCHAR* argv[])
{
CreateFiles();
HZIP hz; DWORD writ;
hz = CreateZip("c:\\Radar.zip", 0);//创建压缩文件
ZipAdd(hz ,"data.txt", "\\data.txt");
CloseZip(hz);
    DeleteFile("c:\\data.txt");//删除txt文件
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Java的commons-compress库实现zip文件分卷压缩的示例代码: ```java import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.compress.utils.IOUtils; public class ZipFileSplitter { private static final int BUFFER_SIZE = 4096; private static final int MAX_SEGMENT_SIZE = 10 * 1024 * 1024; // 10 MB public static void splitZipFile(File inputFile) throws IOException { FileInputStream fileInputStream = new FileInputStream(inputFile); BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream); ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(inputFile.getName() + ".zip"))); zipArchiveOutputStream.setMethod(ZipOutputStream.DEFLATED); int currentSegment = 0; long currentSegmentSize = 0; byte[] buffer = new byte[BUFFER_SIZE]; ZipEntry entry; while ((entry = zipArchiveOutputStream.getNextEntry()) != null) { zipArchiveOutputStream.putArchiveEntry(entry); int count; while ((count = bufferedInputStream.read(buffer, 0, BUFFER_SIZE)) != -1) { zipArchiveOutputStream.write(buffer, 0, count); currentSegmentSize += count; if (currentSegmentSize >= MAX_SEGMENT_SIZE) { zipArchiveOutputStream.closeArchiveEntry(); zipArchiveOutputStream.finish(); zipArchiveOutputStream.close(); currentSegment++; currentSegmentSize = 0; zipArchiveOutputStream = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(inputFile.getName() + ".part" + currentSegment + ".zip"))); zipArchiveOutputStream.setMethod(ZipOutputStream.DEFLATED); entry = new ZipEntry(entry.getName()); zipArchiveOutputStream.putArchiveEntry(entry); } } zipArchiveOutputStream.closeArchiveEntry(); zipArchiveOutputStream.finish(); zipArchiveOutputStream.close(); bufferedInputStream.close(); fileInputStream.close(); } } public static void main(String[] args) { try { File inputFile = new File("example.txt"); splitZipFile(inputFile); } catch (IOException e) { e.printStackTrace(); } } } ``` 该示例代码可以将一个zip文件分割成多个部分,每个部分最大为10MB,并将它们压缩成单独的zip文件。该代码使用了commons-compress库的ZipArchiveOutputStream类来创建压缩文件,使用了ZipEntry类来表示每个条目,并使用了缓冲输入流和缓冲输出流来提高读写效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值