zoukankan      html  css  js  c++  java
  • C#文件操作

    public static void Compress(string sourceFile, string destFile)
            {
                FileStream fs = File.OpenRead(sourceFile);
                byte[] bs = new byte[fs.Length];
                fs.Read(bs, 0, bs.Length);
                fs.Close();
    
                FileStream fd = File.Create(destFile);
                GZipStream gs = new GZipStream(fd, CompressionMode.Compress);
                //DeflateStream ds = new DeflateStream(fs, CompressionMode.Compress);
                gs.Write(bs, 0, bs.Length);
                gs.Close();
                fd.Close();
    
            }
    
            public static void Decompress(string sourceFile, string destFile)
            {
                FileStream fs = File.OpenRead(sourceFile);
                FileStream fd = File.Create(destFile);
                GZipStream gs = new GZipStream(fs, CompressionMode.Decompress);
                //byte[] bs = new byte[gs.Length];
                //gs.Read(bs, 0, bs.Length);
                //gs.Close();
                //fs.Close();
                //fd.Write(bs, 0, bs.Length);
                //fd.Flush();
                //fd.Close();
                int b = gs.ReadByte();
                while (b != -1)
                {
                    fd.WriteByte((byte)b);
                    b = gs.ReadByte();
                }
                fd.Flush();
                fd.Close();
                gs.Close();
                fs.Close();
    
            }

    单文件压缩与解压

  • 相关阅读:
    data guard switchover切换异常
    oracle dataguard
    建立信任关系
    sqlplus 打印很乱,而且很短就换行
    老友记英语
    每天读一遍
    extern的用法
    linux信号处理
    http server v0.1_http_parse.c
    http server v0.1_http_webapp.c
  • 原文地址:https://www.cnblogs.com/tgdjw/p/4505417.html
Copyright © 2011-2022 走看看