解压缩C#中的错误 [英] decompress error in c#

查看:291
本文介绍了解压缩C#中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码解压缩.gz文件

但出现错误"CopyTo方法不存在"

Hi I am using following code to decompress a .gz file

but getting an error "CopyTo Method does not exist"

private void Decompress(string file)
        {
            FileInfo fi = new FileInfo(file);

            // Get the stream of the source file.
            using (FileStream inFile = fi.OpenRead())
            {
                // Get original file extension, for example
                // "doc" from report.doc.gz.
                string curFile = fi.FullName;
                string origName = curFile.Remove(curFile.Length -
                        fi.Extension.Length);

                //Create the decompressed file.
                using (FileStream outFile = System.IO.File.Create(origName))
                {
                    using (GZipStream Decompress = new GZipStream(inFile,
                            CompressionMode.Decompress))
                    {
                        // Copy the decompression stream
                        // into the output file.
                        <big>Decompress.CopyTo(outFile);</big>                    }
                }
            }
        }



请帮助



please help

推荐答案

您是否已包含以下命名空间: System.IO.Compression

我看到您已经复制粘贴了此处提供的示例: http://msdn.microsoft.com/zh-我们/library/ms404280.aspx [ ^ ]

如果您注意到,上面的代码中的Decompress对象是 GZipStream类的对象 [^ ].它确实具有公开的属性CopyTo: MSDN:Stream.CopyTo方法(流) [ ^ ],它从当前流中读取字节,并将它们写入目标流.

确保您有完整的程序要执行.
Have you included this namespace: System.IO.Compression

I see you have copy-pasted the sample given here: http://msdn.microsoft.com/en-us/library/ms404280.aspx[^]

If you notice, Decompress object in the code above is an object of GZipStream Class[^]. It does have a property CopyTo exposed: MSDN: Stream.CopyTo Method (Stream)[^] that reads the bytes from the current stream and writes them to the destination stream.

Make sure you have a complete program to execute.


这篇关于解压缩C#中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆