Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将.zip文件转换为字节数组,并从字节数组重新创建.zip_C#_.net_Zip - Fatal编程技术网

C# 将.zip文件转换为字节数组,并从字节数组重新创建.zip

C# 将.zip文件转换为字节数组,并从字节数组重新创建.zip,c#,.net,zip,C#,.net,Zip,我已将.zip文件转换为字节[],现在我正尝试将字节[]转换回原始的.zip文件。我尝试过的选项已经用尽了。有人给我一个指针,我怎样才能做到这一点?您想要: 您可能不想先将原始zip文件读入字节数组,然后再尝试解压缩它。相反,请通过此帮助器方法访问它 注意使用ZipArchive.Entries访问存储在单个zip存档中的子文件;当我第一次学习使用zip文件时,这让我大吃一惊。您想要: 您可能不想先将原始zip文件读入字节数组,然后再尝试解压缩它。相反,请通过此帮助器方法访问它 注意使用ZipA

我已将.zip文件转换为字节[],现在我正尝试将字节[]转换回原始的.zip文件。我尝试过的选项已经用尽了。有人给我一个指针,我怎样才能做到这一点?

您想要:

您可能不想先将原始zip文件读入字节数组,然后再尝试解压缩它。相反,请通过此帮助器方法访问它

注意使用
ZipArchive.Entries
访问存储在单个zip存档中的子文件;当我第一次学习使用zip文件时,这让我大吃一惊。

您想要:

您可能不想先将原始zip文件读入字节数组,然后再尝试解压缩它。相反,请通过此帮助器方法访问它


注意使用
ZipArchive.Entries
访问存储在单个zip存档中的子文件;当我第一次学习使用zip文件时,这让我大吃一惊。

你知道吗,你通过阅读将文件变成了字节数组?执行与.File.writealBytes(pathToSave)相反的操作您知道您通过读取操作将文件转换为字节数组吗?执行与.File.writealBytes(路径保存)相反的操作
using (ZipArchive zip = ZipFile.Open("test.zip", ZipArchiveMode.Create))
{
    var entry = zip.CreateEntry("File Name.txt");
    using (StreamWriter sw = new StreamWriter(entry.Open()))
    {
        sw.Write("Some Text");  
    }
}

using (ZipArchive zip = ZipFile.Open("test.zip", ZipArchiveMode.Read))
{
    foreach (ZipArchiveEntry entry in zip.Entries)
    {
        using (StreamReader sr = new StreamReader(entry.Open()))
        {
            var result = sr.ReadToEnd();
        }
    }
}