Zip 压缩
Posted Andy·Li
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zip 压缩相关的知识,希望对你有一定的参考价值。
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 压缩的主要内容,如果未能解决你的问题,请参考以下文章