zoukankan      html  css  js  c++  java
  • 解压缩

    
    

    需要下载引用ICSharpCode.SharpZipLib.dll这个文件


    using
    ICSharpCode.SharpZipLib.Zip; using System.IO; ///////////////////////////////////调用//////////////////////////////////// string filePath = GetRootPath() + "UploadFiles\test\aaa.zip"; string destFilePath = GetRootPath() + "UploadFiles\test\"; UnZip(filePath, destFilePath, ""); ////////////////////////////////////////////////////////////////////////////// #region 解压 /// <summary> /// 解压 /// </summary> /// <param name="fileToUpZip">压缩文件路径</param> /// <param name="zipedFolder">解压文件存放路径,为空时默认创建文件夹</param> /// <param name="password">密码</param> public void UnZip(string fileToUpZip, string zipedFolder, string password) { if (!File.Exists(fileToUpZip)) { return; } if (!Directory.Exists(zipedFolder)) { Directory.CreateDirectory(zipedFolder); } ZipInputStream s = null; ZipEntry theEntry; string fileName; FileStream streamWriter = null; try { s = new ZipInputStream(File.OpenRead(fileToUpZip)); s.Password = password; while ((theEntry = s.GetNextEntry()) != null) { if (theEntry.Name != String.Empty) { fileName = Path.Combine(zipedFolder, theEntry.Name); //判断文件路径是否是文件夹 if (fileName.EndsWith("/") || fileName.EndsWith("\")) { Directory.CreateDirectory(fileName); continue; } streamWriter = File.Create(fileName); int size; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } } } } finally { if (streamWriter != null) { streamWriter.Close(); } if (s != null) { s.Close(); } GC.Collect(); GC.Collect(1); } } #endregion
  • 相关阅读:
    Windows 服务程序(一)
    API---注册表编程
    API---文件操作
    main(argc, char *argv[])
    C 自删除技术---批处理方式
    分治法排序
    TDD尝试:nodejs单元测试
    尝试create tech team
    Yum重装走过的坑
    求生欲很强的数据库
  • 原文地址:https://www.cnblogs.com/deep-blue/p/5110001.html
Copyright © 2011-2022 走看看