C# 解压及压缩文件源代码
2024-10-01 12:03:53
using System.IO;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Checksums;
public void unZip(string strSouceFile, string strDestFile)
{
if (!Directory.Exists(strDestFile))
Directory.CreateDirectory(strDestFile);
using (ZipInputStream zip = new ZipInputStream(File.OpenRead(strSouceFile)))
{
ZipEntry theEntry;
string fileName;
FileStream streamWriter;
while ((theEntry = zip.GetNextEntry()) != null)
{
fileName = Path.GetFileName(theEntry.Name); if (fileName != String.Empty)
{
streamWriter = new FileStream(strDestFile + fileName, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Write); int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = zip.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size); }
else
{
break;
}
}
streamWriter.Close();
}
}
MessageBox.Show("解压文件成功! ","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
} public void ZipFile(string strSouceFile, string strDestFile)
{
using (ZipOutputStream stream = new ZipOutputStream(File.Create(strDestFile)))
{
stream.SetLevel(5);
byte[] buffer = new byte[0x1000];
ZipEntry entry = new ZipEntry(Path.GetFileName(strSouceFile));
entry.DateTime = DateTime.Now;
stream.PutNextEntry(entry);
using (FileStream stream2 = File.OpenRead(strSouceFile))
{
int num;
do
{
num = stream2.Read(buffer, 0, buffer.Length);
stream.Write(buffer, 0, num);
}
while (num > 0);
MessageBox.Show("压缩文件成功! ");
}
stream.Finish();
stream.Close();
}
}
须要引用的dll,下载下面页面的dll
http://download.csdn.net/detail/sky_cat/7236675
最新文章
- 【安装MongoDB】CentOS7 下安装NodeJs+Express+MongoDB+Redis
- python对XML的解析
- TreeMap 的实现
- JMeter中的关联-正则表达式提取(1)
- http 响应码
- jsp中将后台传递过来的json格式的list数据绑定到下拉菜单select
- C++ Preprosessor import
- oracle系列--解锁数据库
- [刷题]Codeforces 746G - New Roads
- fiddler安装及配置+利用fiddler进行简单抓包(wawayaya阅读)
- C#中DataTable与XML格式的相互转换
- 1.3 第一个python程序
- 【Java】浅谈Java IO
- c#如何判断字符串是否含中文
- 积跬步,聚小流-------js实现placeholder的效果
- CCPC-Wannafly Winter Camp Day7 (Div2, onsite)
- wifi钓鱼 强势拿你的wifi密码
- jquery加载解析XML文件
- 【spring cloud】spring cloud分布式服务eureka启动时报错:java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<;init>;([Ljava/lang/Object;)V
- 【占位】HihoCoder 1160 : 攻城略地(并查集好题)
热门文章
- Docker学习总结(13)——从零开始搭建Jenkins+Docker自动化集成环境
- bzoj3626【LNOI2014】LCA
- mybatis和hibernate的区别【转】
- hdoj 1013Digital Roots
- linux定时备份mysql数据库文件
- STL 之 iterator traits 备忘
- hdu-3401-Trade-单调队列优化的DP
- Python爬糗百热门20条并邮件分发+wxPython简易GUI+py2app转成可运行文件
- [Android] Android开发优化之——对界面UI的优化(2)
- 子文件夹的遍历(python、matlab)