利用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 ...
随机推荐
- Mybatis批量插入oracle,mysql
oracle <insert id="addUserData" parameterType="java.util.List"> INSERT IN ...
- POJ 3335 Rotating Scoreboard(半平面交求多边形核)
题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...
- tomcat console
1.大家都知道,在Tomcat5及其以后的版本中,当启动tomcat之后,是看不到控制台中的manager应用的.Manager的应用还是很有好处的,可以直接在控制台上(类似于weblogic上的co ...
- 错误:error libGL.so: cannot open shared object file: No such file or directory
Failed to load libGL.soerror libGL.so: cannot open shared object file: No such file or directory 启动e ...
- idea新建maven项目时,mvn archetype:generate 速度缓慢
原文 idea新建maven项目时,mvn archetype:generate 速度缓慢 1 现象: 用IDEA新建maven项目,填写完各种参数,创建时,控制台卡在“[INFO] Generati ...
- ubuntu 12.04安装vncserver
1.安装桌面 apt-get install ubuntu-desktop 2.安装vncserver apt-get install vnc4server 3.设置vncserver密码 vncpa ...
- Model的绑定
ReflectedControllerDescriptor:ControllerDescriptor Controller的 public override ActionDescriptor Find ...
- LA 4255 Guess
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 索引 split2
当往一个已经满了的索引块中插入新的索引条目时,将发生索引块的split,在9i下,分两种不同的情况进行split: (1)如果插入的索引键值不是最大的,将发生50-50的split,也就是说有bloc ...
- samba linux windows 请联系管理员
在使用Samba进行建立Window与Linux共享时,要是不能访问,出现“您可能没有权限使用网络资源”, 那就是SELinux在作怪了 要是想让共享目录能访问,可以使用命令 #setenforce ...