压缩文件

示例代码:

       string filepath = Server.MapPath("Textfile.txt");
        FileStream infile = File.OpenRead(filepath);
        byte[] buffer = new byte[infile.Length];
        infile.Read(buffer, 0, buffer.Length);
        infile.Close();
        FileStream outfile=File.Create(Path.ChangeExtension(filepath,"zip"));
        GZipStream gzipstream=new GZipStream(outfile,CompressionMode.Compress);
        gzipstream.Write(buffer,0,buffer.Length);
        gzipstream.Close();
      

posted @ 2011-02-11 09:37  IT苦行僧  阅读(153)  评论(0编辑  收藏  举报