我正在使用以下 C# 代码来压缩文件:
// Open the stream we want to compress
FileStream fs = File.Create(@"C:\Projects\Samples\test\compressed.zip", 0);
// Creates the GZipStream
GZipStream gzip = new GZipStream(fs, CompressionMode.Compress);
// Reading the content to compress
byte[] bytes = File.ReadAllBytes(@"C:\Projects\Samples\samplefile.xml");
// Writing compressed content
gzip.Write(bytes, 0, bytes.Length);
gzip.Close(); // This also closes the FileStream (the underlying stream)
但是,当我从 Windows 资源管理器中提取文件时,该文件会丢失其扩展名,因此它不再是 samplefile.xml,而是变成了 samplefile。.txt 文件发生了同样的事情,而不仅仅是 .xml 文件。
你能帮我看看我做错了什么吗?