首页 > Windows开发 > 详细

C#解压缩文件

时间:2016-04-19 13:48:21      阅读:371      评论:0      收藏:0      [点我收藏+]

代码:

技术分享
#region 解压
/// <summary>
/// 解压
/// </summary>
public void UnZip(string zipPath, string targetPath)
{
    using (FileStream fsZip = new FileStream(zipPath, FileMode.Open, FileAccess.Read))
    {
        using (ZipInputStream zipInputStream = new ZipInputStream(fsZip))
        {

            ZipEntry zipEntry;
            while ((zipEntry = zipInputStream.GetNextEntry()) != null)
            {
                if (zipEntry.IsDirectory)
                {
                    Directory.CreateDirectory(Path.Combine(targetPath, zipEntry.Name));
                }
                else
                {
                    if (zipEntry.Name != String.Empty)
                    {
                        //解压文件到指定的目录
                        using (FileStream fsFile = new FileStream(Path.Combine(targetPath, zipEntry.Name), FileMode.Create, FileAccess.Write))
                        {
                            int size;
                            byte[] data = new byte[1024 * 1024];
                            while ((size = zipInputStream.Read(data, 0, data.Length)) > 0)
                            {
                                fsFile.Write(data, 0, size);
                            }
                        }
                    }
                }
            }//end while
        }
    }
}
#endregion
View Code

 

C#解压缩文件

原文:http://www.cnblogs.com/s0611163/p/5407722.html

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