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