c# – GZipStream工作但扩展丢失
发布时间:2020-12-15 18:05:51 所属栏目:百科 来源:网络整理
导读:我使用下面的代码来压缩文件,它工作正常但是当我用WinRar解压缩时,我得到没有扩展名的原始文件名,任何线索为什么如果我解压缩文件名是myReport.xls我只得到myReport? using (var fs = new FileStream(fileName,FileMode.Open)){ byte[] input = new byte[fs
我使用下面的代码来压缩文件,它工作正常但是当我用WinRar解压缩时,我得到没有扩展名的原始文件名,任何线索为什么如果我解压缩文件名是myReport.xls我只得到myReport?
using (var fs = new FileStream(fileName,FileMode.Open)) { byte[] input = new byte[fs.Length]; fs.Read(input,input.Length); fs.Close(); using (var fsOutput = new FileStream(zipName,FileMode.Create,FileAccess.Write)) using(var zip = new GZipStream(fsOutput,CompressionMode.Compress)) { zip.Write(input,input.Length); zip.Close(); fsOutput.Close(); } } 解决方法
GZip只压缩一个文件 – 不知道名字.因此,如果压缩文件myReport.xls,则应将其命名为myReport.xls.gz.在解压缩时,将删除最后一个文件扩展名,因此您最终得到原始文件名.
它是如何在Unix / Linux中使用它的方式… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |