c#文件解压缩

来源:互联网 发布:设计电路板的软件 编辑:程序博客网 时间:2024/04/30 12:00

关于解压缩的例子很多,大都雷同,本文代码读取压缩包中特定文件。

添加引用

using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.Zip;
using System.Drawing;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.BZip2; 

 ZipFile zip = new ZipFile("E://1.zip");   压缩文件路径
        foreach (ZipEntry entry in zip)  遍历文件
        {
            if (entry.IsFile && (entry.Name.EndsWith(".jpg") || entry.Name.EndsWith(".JPG"))) 是否有你需要的类型文件
            {
                string filename =   Path.GetFileName(entry.Name);        得到此文件名
                 byte[] data = new byte[8192]; 定义一个数组接收,此数组不能定义为stream的长度,如定义为长度则为零,不能接收到数据
                 Stream gs = zip.GetInputStream(entry); 得到此文件流
                 gs.Read(data, 0, data.Length); 读入
            }

本文为科雅客原创,转载请注明