C# .NET 压缩ZIP时 OOM OutOfMemoryException

发布时间 2023-04-12 14:23:31作者: runliuv

C# .NET 压缩ZIP时 OOM OutOfMemoryException.

ZipArchiveEntry、ZipEntry、SharpZipLib、ZipOutputStream、OutOfMemoryException.

 

解决方法:

可以把零散的文件,存到某个文件夹。再调用ZipFile.CreateFromDirectory来压缩。

using System.IO.Compression;

Console.WriteLine("Hello, World!");


string startPath = @"E:\迅雷下载\temp1";
string zipPath = @"E:\迅雷下载\temp1.zip";
string extractPath = @"E:\迅雷下载\extract";

Console.WriteLine("开始压缩!");

ZipFile.CreateFromDirectory(startPath, zipPath);

Console.WriteLine("开始解压!");

ZipFile.ExtractToDirectory(zipPath, extractPath);

Console.WriteLine("解压完成!");
Console.ReadKey();

 

-