最简单的压缩代码 static string InFilePath = @" C:\Documents and Settings\wuy\桌面\新建 文本文档.txt " ; static string OutFilePath = @" C:\Documents and Settings\wuy\桌面\新建 文本文档.zip " ; private void button1_Click( object sender, EventArgs e) { FileInfo file = new FileInfo(InFilePath); Crc32 crc = new Crc32(); ZipOutputStream ou=new ZipOutputStream(File.Create(OutFilePath)); ou.SetLevel(9); //压缩等级,越第越大 0~9; FileStream fs = File.OpenRead(InFilePath); Byte[] buffer = new byte[file.Length]; fs.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry("aa.txt"); //压缩后的文件属性 //entry.DateTime = DateTime.Now; //entry.Size = fs.Length; fs.Close(); //crc.Reset(); //内存算法,基本没用 // crc.Update(buffer); //entry.Crc = crc.Value; ou.PutNextEntry(entry); ou.Write(buffer, 0, buffer.Length); ou.Finish(); ou.Close(); } posted on 2006-11-07 15:38 吴勇 阅读( ...) 评论( ...) 编辑 收藏 转载于:https://www.cnblogs.com/wuyong/archive/2006/11/07/553006.html