Mig*_*ura 2 c# .net-core asp.net-core c#-7.0
在 Net Core 2.1 上,我试图从 ZIP 存档中读取文件。
我需要将每个文件内容转换为 Byte[] 所以我有:
using (ZipArchive archive = ZipFile.OpenRead("Archive.zip")) {
foreach (ZipArchiveEntry entry in archive.Entries) {
using (Stream stream = entry.Open()) {
Byte[] file = new Byte[stream.Length];
stream.Read(file, 0, (Int32)stream.Length);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到错误:
Exception has occurred: CLR/System.NotSupportedException
An exception of type 'System.NotSupportedException' occurred in System.IO.Compression.dll but was not handled in user code:
'This operation is not supported.' at System.IO.Compression.DeflateStream.get_Length()
Run Code Online (Sandbox Code Playgroud)
如何将每个文件的内容放入 Byte[] 中?
尝试做这样的事情:
using (ZipArchive archive = ZipFile.OpenRead("archieve.zip"))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
using (Stream stream = entry.Open())
{
byte[] bytes;
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
bytes = ms.ToArray();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
624 次 |
| 最近记录: |