gpt4 book ai didi

c# - GZipStream zip文件无效或损坏

转载 作者:太空宇宙 更新时间:2023-11-03 17:36:58 25 4
gpt4 key购买 nike

打开zip文件时出现问题。我正在使用以下代码来压缩文件:

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文件。这是我的函数调用代码:

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


这是我收到的错误消息:


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

最佳答案

GZipStream不会创建.zip文件。它创建.gz文件。如果需要创建.zip文件,则应使用SharpZipLib之类的东西。

关于c# - GZipStream zip文件无效或损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1327997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com