惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Application and Cybersecurity Blog
Application and Cybersecurity Blog
NISL@THU
NISL@THU
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
T
Troy Hunt's Blog
U
Unit 42
Forbes - Security
Forbes - Security
J
Java Code Geeks
P
Privacy International News Feed
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
H
Heimdal Security Blog
量子位
Martin Fowler
Martin Fowler
G
Google Developers Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
Docker
罗磊的独立博客
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
Simon Willison's Weblog
Simon Willison's Weblog
N
News and Events Feed by Topic
D
DataBreaches.Net
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
S
Secure Thoughts
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - sig556

微信小程序开发需要注意的30个坑 数字证书制作及程序集签名 JAVA和android 环境配置 硬盘安装win2003 MongoDb使用 配置 Win7 和 IIS7 以支持WCF WCF X.509证书验证 IIS+PHP ,apache+Php架设 - sig556 - 博客园 Ubuntu Server学习笔记 FCKeditor 上传自动重命名、按月创建文件夹和基本操作 [转] 软件测试计划模板 web测试的一些经验分享 软件测试流程实施方案 一些常用的正则表达式 - sig556 - 博客园 ASP.net国际化--页面可以选择输出语言 - sig556 - 博客园 项目开发过程文档 PostSharp - Lightweight Aspect-Oriented System 需求管理工具DOORS介绍 [转] B/S 系统界面设计规范
SharpZipLib使用示例
sig556 · 2010-07-03 · via 博客园 - sig556

SharpZipLib 是一个免费的Zip操作类库,可以利用它对 ZIP 等多种格式进行压缩与解压。SharpZipLib使用C#编写的,在VB.NET、C#或其他的.NET语言中都可以使用它创建Zip文件、并进行读取和更新等操作。下载网址:http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx。目前的版本为0.85。

1、创建zip文件,并添加文件:

  1. using (ZipFile zip = ZipFile.Create(@"E:\test.zip")) 
  2.     zip.BeginUpdate(); 
  3.     zip.Add(@"E:\文件1.txt"); 
  4.     zip.Add(@"E:\文件2.txt"); 
  5.     zip.CommitUpdate(); 

2、将文件夹压缩为文件:
(new FastZip()).CreateZip(@"E:\test.zip", @"E:\test\", true, "");
最后一个参数是使用正则表达式表示的过滤文件规则。CreateZip方法有3个重载版本,其中有目录过滤参数、文件过滤参数及用于指定是否进行子目录递归的一个bool类型的参数。
3、将文件添加到已有zip文件中:
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
    zip.BeginUpdate();
    zip.Add(@"E:\test.doc");
    zip.CommitUpdate();
}
4、列出zip文件中文件
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
    string list = string.Empty;
    foreach (ZipEntry entry in zip)
    {
        list += entry.Name + "\r\n";
    }
    MessageBox.Show(list);
}
5、删除zip文件中的一个文件
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
    zip.BeginUpdate();
    zip.Delete(@"test.doc");
    zip.Delete(@"test22.txt");
    zip.CommitUpdate();
}
6、解压zip文件中文件到指定目录下
(new FastZip()).ExtractZip(@"E:\test.zip", @"E:\test\", "");
7、常用类:
ZipInputStream、GZipInputStream用于解压缩Deflate、GZip格式流,ZipOutputStream、GZipOutputStream用于压缩Deflate、GZip格式流。
StreamUtil类包含了几个Stream处理辅助方法:
    ①、Copy(Stream, Stream, Byte[])用于从一个Stream对象中复制数据到另一Stream对象。有多个重写
    ②、ReadFully(Stream, Byte [])用于从Stream对象中读取所有的byte数据。有多个重写