zoukankan      html  css  js  c++  java
  • (原创)文件压缩代码

     #region  文件压缩
            /// <summary>
            /// 文件压缩
            /// </summary>
            /// <param name="M_str_DFile">压缩前文件及路径</param>
            /// <param name="M_str_CFile">压缩后文件及路径</param>
            public void compressFile(string M_str_DFile, string M_str_CFile)
            {
                if (!File.Exists(M_str_DFile)) throw new FileNotFoundException();
                using (FileStream sourceStream = new FileStream(M_str_DFile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    byte[] buffer = new byte[sourceStream.Length];
                    int checkCounter = sourceStream.Read(buffer, 0, buffer.Length);
                    if (checkCounter != buffer.Length) throw new ApplicationException();
                    using (FileStream destinationStream = new FileStream(M_str_CFile, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        using (GZipStream compressedStream = new GZipStream(destinationStream, CompressionMode.Compress, true))
                        {
                            compressedStream.Write(buffer, 0, buffer.Length);
                        }
                    }
                }
            }
  • 相关阅读:
    设计模式-17-迭代器
    设计模式-16-备忘录
    微服务架构设计
    数据库拆分案例
    生成多个git ssh密钥
    分布式数据中间件TDDL、Amoeba、Cobar、MyCAT架构比较
    maven工程 java 实现文件上传 SSM ajax异步请求上传
    MySQL的分区、分表、集群
    Redis实现分布式锁原理与实现分析
    关于消息队列的使用
  • 原文地址:https://www.cnblogs.com/ghfsusan/p/1539266.html
Copyright © 2011-2022 走看看