網(wǎng)站首頁 編程語言 正文
一、介紹
SharpZipLib是一個(gè)完全由C#編寫的ZIP,GZIP,Tar和BZIP2 Library,可以方便的支持這幾種格式的壓縮和解壓縮。
https://github.com/icsharpcode/SharpZipLib?下載解壓SharpZipLib ,將 ICSharpCode.SharpZipLib .dll 添加至項(xiàng)目引用中.
二、操作指南
1.1? 創(chuàng)建zip文件,并添加文件:
using (ZipFile zip = ZipFile.Create(@"E:\test.zip"))
{
zip.BeginUpdate();
zip.Add(@"E:\文件1.txt");
zip.Add(@"E:\文件2.txt");
zip.CommitUpdate();
}
1.2 將文件夾壓縮為文件
(new FastZip()).CreateZip(@"E:\test.zip", @"E:\test\", true, "");
最后一個(gè)參數(shù)是使用正則表達(dá)式表示的過濾文件規(guī)則。CreateZip方法有3個(gè)重載版本,其中有目錄過濾參數(shù)、文件過濾參數(shù)及用于指定是否進(jìn)行子目錄遞歸的一個(gè)bool類型的參數(shù)。
1.3 將文件添加到已有zip文件中
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
zip.BeginUpdate();
zip.Add(@"E:\test.doc");
zip.CommitUpdate();
}
1.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);
}
1.5? 刪除zip文件中的一個(gè)文件
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
zip.BeginUpdate();
zip.Delete(@"test.doc");
zip.Delete(@"test22.txt");
zip.CommitUpdate();
}
1.6 解壓zip文件中文件到指定目錄下
(new FastZip()).ExtractZip(@"E:\test.zip", @"E:\test\", "");
三、 常用類
ZipInputStream、GZipInputStream用于解壓縮Deflate、GZip格式流,
ZipOutputStream、GZipOutputStream用于壓縮Deflate、GZip格式流。
StreamUtil類包含了幾個(gè)Stream處理輔助方法:
1) Copy(Stream, Stream, Byte[])用于從一個(gè)Stream對象中復(fù)制數(shù)據(jù)到另一Stream對象。有多個(gè)重寫。
2) ReadFully(Stream, Byte [])用于從Stream對象中讀取所有的byte數(shù)據(jù)。有多個(gè)重寫。
原文鏈接:https://www.cnblogs.com/springsnow/p/9399292.html
相關(guān)推薦
- 2022-11-26 使用HttpClient消費(fèi)ASP.NET?Web?API服務(wù)案例_實(shí)用技巧
- 2022-12-15 QT中對話框的使用示例詳解_C 語言
- 2022-10-01 iOS簡單實(shí)現(xiàn)輪播圖效果_IOS
- 2022-11-07 react使用websocket實(shí)時(shí)通信方式_React
- 2022-10-15 python中mpi4py的所有基礎(chǔ)使用案例詳解_python
- 2022-09-10 關(guān)于pandas.date_range()的用法及說明_python
- 2022-11-01 Kotlin語言使用BroadcastReceiver示例介紹_Android
- 2023-01-11 jQuery綁定點(diǎn)擊事件與改變事件的方式總結(jié)及多個(gè)元素綁定多個(gè)事件_jquery
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支