使用C#进行文件压缩 [英] Files Compression using C#
本文介绍了使用C#进行文件压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码进行压缩,
i used this code for compression,
string fileToBeCompressed="E:\\access.accdb";
string t = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
string zipFilename = "E:\\"+t+".zip";
FileStream target = new FileStream(zipFilename, FileMode.Create, FileAccess.Write);
GZipStream alg = new GZipStream(target, CompressionMode.Compress);
byte[] data = File.ReadAllBytes(fileToBeCompressed);
alg.Write(data, 0, data.Length);
alg.Flush();
target.Close();
运行此代码后,我检查了E驱动器并找到了文件t.zip 。
但是当我想在这里制作Extract时,CRC文件中会出现错误信息
如何解决这个问题。
After run this code, i checked the E drive and found the file t.zip.
but when i want to make Extract here ,there is error message come in CRC for that file
how can i solve this problem .
推荐答案
GZipStream不压缩成ZIP格式 - 而是保存到GZip。这可以使用Winzip打开,但只有在您更改文件扩展名时:尝试
GZipStream does not compress into ZIP format- it saves to GZip instead. This is openable using Winzip, but only if you change the file extension: try
string zipFilename = "E:\\"+t+".accdb.gz";
而不是。
(您还需要文件扩展名,否则它不能很好地解压缩)
instead.
(You need the file extension as well, or it doesn't decompress so well)
这篇关于使用C#进行文件压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文