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();
    
            }

    单文件压缩与解压

  • 相关阅读:
    2312--1.3.4 Prime Cryptarithm 牛式
    Slava and tanks 877C
    World Cup 996B(排队模拟)
    css内边距 边框
    iframs刷新的两种方法
    JS DOM节点
    JS对话框
    JS事件常用事件
    JS数组
    JS第一天
  • 原文地址:https://www.cnblogs.com/tgdjw/p/4505417.html
Copyright © 2011-2022 走看看