zoukankan      html  css  js  c++  java
  • C# ICSharpCode.SharpZipLib 压缩文件 yang

     
    利用ICSharpCode.SharpZipLib.dll 压缩文件夹
    View Code
     1 private void zip(string strFile, ZipOutputStream s, string staticFile)
     2         {
     3             if (strFile[strFile.Length - 1] != Path.DirectorySeparatorChar)
     4             {
     5                 strFile = strFile + Path.DirectorySeparatorChar;
     6             }
     7             Crc32 crc = new Crc32();
     8             string[] fileSystemEntries = Directory.GetFileSystemEntries(strFile);
     9             foreach (string str in fileSystemEntries)
    10             {
    11                 if (Directory.Exists(str))
    12                 {
    13                     zip(str, s, staticFile);
    14                 }
    15                 else
    16                 {
    17                     FileStream stream = File.OpenRead(str);
    18                     byte[] buffer = new byte[stream.Length];
    19                     stream.Read(buffer, 0, buffer.Length);
    20                     ZipEntry entry = new ZipEntry(str.Substring(staticFile.LastIndexOf(@"\") + 1));
    21                     entry.DateTime=DateTime.Now;
    22                     entry.Size = stream.Length;
    23                     stream.Close();
    24                     crc.Reset();
    25                     crc.Update(buffer);
    26                     entry.Crc=crc.Value;
    27                     s.PutNextEntry(entry);
    28                     s.Write(buffer, 0, buffer.Length);
    29                 }
    30             }
    31         }
    32         /// <summary>
    33         /// 
    34         /// </summary>
    35         /// <param name="strFile">文件夹</param>
    36         /// <param name="strZip">压缩后文件</param>
    37         public void ZipFile(string strFile, string strZip)
    38         {
    39             if (strFile[strFile.Length - 1] != Path.DirectorySeparatorChar)
    40             {
    41                 strFile = strFile + Path.DirectorySeparatorChar;
    42             }
    43             ZipOutputStream s = new ZipOutputStream(File.Create(strZip));
    44             s.Password = "**";//需要密码可以设置
    45             s.SetLevel(6);
    46             zip(strFile, s, strFile);
    47             s.Finish();
    48             s.Close();
    49         }
  • 相关阅读:
    Keras分类问题
    Keras预测股票
    Tensflow预测股票实例
    estimator = KerasClassifier
    keras CNN解读
    Windows下Python安装: requires numpy+mkl 和ImportError: cannot import name NUMPY_MKL
    Tensorflow RNN_LSTM实例
    同时安装python2.7和python3.5
    oracle 杀掉当前用户的进程
    IMP导入时的错误以及解决办法
  • 原文地址:https://www.cnblogs.com/alibaba/p/2619872.html
Copyright © 2011-2022 走看看