首页 > 其他 > 详细

Zip 压缩

时间:2017-01-20 12:38:25      阅读:166      评论:0      收藏:0      [点我收藏+]

ICSharpCode.SharpZipLib.dll

 

using ICSharpCode.SharpZipLib.Zip;

 

string[] filenames = Directory.GetFiles(dirPath);
using (ZipOutputStream s = new ZipOutputStream(File.Create(zipFilePath)))
{
s.Password = password;
s.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
if (file.Contains(fileName))
{
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
}
s.Finish();
s.Close();
}

Zip 压缩

原文:http://www.cnblogs.com/Andy-Li/p/6322386.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!