GZipStream zip 文件无效或损坏 [英] GZipStream zip file invalid or corrupted

查看:65
本文介绍了GZipStream zip 文件无效或损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在打开 zip 文件时遇到问题.我正在使用此代码压缩文件:

I have a problem when opening a zip file. I am using this code to zip the file:

public static string Zip_File(string soruce , string target)
{
    try
    {
        byte[] bufferWrite;               
        using (FileStream fsSource = new FileStream(soruce, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            bufferWrite = new byte[fsSource.Length];
            fsSource.Read(bufferWrite, 0, bufferWrite.Length);
            using (FileStream fsDest = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
            {
                using (GZipStream gzCompressed = new GZipStream(fsDest, CompressionMode.Compress, true))
                {
                    gzCompressed.Write(bufferWrite, 0, bufferWrite.Length);
                    bufferWrite = null;
                    fsSource.Close();
                    gzCompressed.Close();
                    fsDest.Close();
                }
            }
        }
        return "success";
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
}

当我调用此函数时,我收到成功"消息,但无法打开 zip 文件.这是我的函数调用代码:

When I call this function, I am receiving "success" message, but I can't open the zip file. This is my function call code:

ZipFiles.Zip_File(@"C:\Documents and Settings\ccspl\Desktop\IntegrityDVR.mdb", @"C:\Documents and Settings\ccspl\Desktop\a.zip")

这是我收到的错误消息:

This is the error message I receive:

压缩的(文件夹)无效或损坏

the compressed(folder) is invalid or corrupted

推荐答案

GZipStream 不创建 .zip 文件.它创建 .gz 文件.如果您需要创建 .zip 文件,您应该使用类似 SharpZipLib.

GZipStream does not create .zip files. It creates .gz files. If you need to create .zip files, you should use something like SharpZipLib.

这篇关于GZipStream zip 文件无效或损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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