我使用下面的代码来压缩文件,它工作正常但是当我用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中使用它的方式…