利用ICSharpCode.SharpZipLib.Zip进行文件压缩
支持文件和字符压缩。
创建全新的压缩包
第一步,创建压缩包
using ICSharpCode.SharpZipLib.Zip;
ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create(strZipPath));
参数:strZipPath,提供压缩后的文件包全路径,即地址和文件名。如,D:\tmp\01.rar
第二步,向压缩包中添加压缩包的文件名
ICSharpCode.SharpZipLib.Zip.ZipEntry entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(name);
entry.DateTime = System.DateTime.Now;
zipOutputStream.PutNextEntry(entry);
如01.rar压缩包中包含A.txt,B.txt,C.txt三个文件,那么参数name则对应为A.txt,B.txt,C.txt。
第三步,向压缩包中的entry写入文件
System.IO.FileStream fs = System.IO.File.OpenRead(strFile);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, , buffer.Length);
zipOutputStream.Write(buffer, , buffer.Length);
fs.Close();
fs.Dispose();
参数:strFile,待压缩的文件全路径。
第二步、第三步,可以循环,向压缩包中添加更多的文件。
向已有的压缩包中添加新文件
ICSharpCode.SharpZipLib.Zip.ZipFile z = new ICSharpCode.SharpZipLib.Zip.ZipFile();
唯一区别是使用ZipFile代替ZipOutputStream,打开已有的压缩文件。
每天学习,进步一点点。
利用ICSharpCode.SharpZipLib.Zip进行文件压缩的更多相关文章
- C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩 C# 文件压缩加解密
C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩 这里我们选用ICSharpCode.SharpZipLib这个类库来实现我们的需求. 下载地址:http:// ...
- C# 下利用ICSharpCode.SharpZipLib.dll实现文件/目录压缩、解压缩
ICSharpCode.SharpZipLib.dll下载地址 1.压缩某个指定文件夹下日志,将日志压缩到CompressionDirectory文件夹中,并清除原来未压缩日志. #region 压缩 ...
- C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩
这里我们选用ICSharpCode.SharpZipLib这个类库来实现我们的需求. 下载地址:http://icsharpcode.github.io/SharpZipLib/ 1.单个或多个文件加 ...
- c# ICSharpCode.SharpZipLib.Zip实现文件的压缩
首先了解ZipOutPutStream和ZipEntry对象 ZipOutPutStream对象 如果要完成一个文件或文件夹的压缩,则要使用ZipOutputStream类.ZipOutputStre ...
- 使用ICSharpCode.SharpZipLib.Zip实现压缩与解压缩
使用开源类库ICSharpCode.SharpZipLib.Zip可以实现压缩与解压缩功能,源代码和DLL可以从http://www.icsharpcode.net/OpenSource/SharpZ ...
- 基于ICSharpCode.SharpZipLib.Zip的压缩解压缩
原文:基于ICSharpCode.SharpZipLib.Zip的压缩解压缩 今天记压缩解压缩的使用,是基于开源项目ICSharpCode.SharpZipLib.Zip的使用. 一.压缩: /// ...
- C#使用ICSharpCode.SharpZipLib.dll进行文件的压缩与解压
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- 利用ICSharpCode.SharpZipLib进行压缩
#ZipLib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. It is im ...
- 使用NPOI读取Excel报错ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature
写了一个小程序利用NPOI来读取Excel,弹出这样的报错: ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature ...
随机推荐
- 自动化 测试框架部署(python3+selenium2)
安装Python 从https://www.python.org/downloads/下载最新版本的Python3,请注意,是3: 需要将Python的安装目录和安装目录下的Scripts文件夹添加到 ...
- Hadoop教程之编写HelloWorld(2)
前面我们写了一个Hadoop程序,并让它跑起来了.但想想不对啊,Hadoop不是有两块功能么,DFS和MapReduce.没错,上一节我们写了一个MapReduce的HelloWorld程序,那这一节 ...
- SQLHelper.cs的经典代码-存储过程
using System; using System.Collections.Generic; using System.Text; using System.Collections; using S ...
- RxJava+Retrofit+MVP构建的App——聚合资讯
RtfRxMVP 聚合资讯APP,提供热点资讯,天气预报以及笑话精选服务,使用 Retrofit + RxJava + MVP 构建代码. Hello U 这是我的一个练习项目,第一次尝试运用 MVP ...
- MyEclipse6.6 汉化过程
...
- Eclipse集成Tomcat的配置步骤实例
使用Eclipse开发B/S结构Web应用时,必须使用Web应用服务器,常见的应用服务器有Tomcat, Jboss, WebLogic, WebSphere, SUN System Applicat ...
- [原]poj-2680-Choose the best route-dijkstra(基础最短路)
题目大意: 已知n 个点,m条路线,s为终点:给出m条路线及其权值:给出w个起点,求最短路! 思路:基础的dijkstra,有向无环正权最短路,只要把终点和起点 reverse考虑便可. AC代码如下 ...
- Android HTTPS(1)概念和简单示例
Security with HTTPS and SSL The Secure Sockets Layer (SSL)—now technically known as Transport Layer ...
- BISTU-(1)-4-17-2016
A:贪心,遍历每次维护一个最便宜的价格,假如当前价格不如此前价格,就用此前价格购买当前数量的肉,每次更新最便宜的价格. #include <algorithm> #include < ...
- Android Wear开发者预览配置过程
第一步Android SDK Manager 中 1.升级Android SDK Tools到22.6+版本2.Android 4.4.2 下 安装 Android Wear ARM EABI v7a ...