我想使用.NET框架中包含的GZipStream类来解压缩(.gz)文件。我正在使用MSDN文档,并不断收到此异常:“不支持写入压缩流。”不支持写入压缩流。使用System.IO.GZipStream
这里是应用程序源:
try
{
var infile = new FileStream(@"C:\TarDecomp\TarDecomp\TarDecomp\bin\Debug\nick_blah-2008.tar.gz", FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[infile.Length];
// Read the file to ensure it is readable.
int count = infile.Read(buffer, 0, buffer.Length);
if (count != buffer.Length)
{
infile.Close();
Console.WriteLine("Test Failed: Unable to read data from file");
return;
}
infile.Close();
MemoryStream ms = new MemoryStream();
// Use the newly created memory stream for the compressed data.
GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress, true);
Console.WriteLine("Decompression");
compressedzipStream.Write(buffer, 0, buffer.Length);
// Close the stream.
compressedzipStream.Close();
Console.WriteLine("Original size: {0}, Compressed size: {1}", buffer.Length, ms.Length);
例外是在compressedZipStream.write抛出()。
任何想法?这个异常告诉我什么?谢谢!
我试着这个谢谢你。 – Nick 2009-08-30 19:25:56
你的男人..谢谢! – Nick 2009-08-30 19:27:03
很高兴提供帮助。 :) – 2009-08-30 19:35:04