我有以下代码,即create一个新的zip文件,然后add entry使用NoCompressionie 将该文件压缩到该文件,ZERO compression ratio然后尝试将其作为普通文本读取。
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
using (FileStream zipToOpen = new FileStream(@"d:\release.zip", FileMode.Create))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
{
ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt", CompressionLevel.NoCompression);
using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
{
writer.WriteLine("Information about this package.");
writer.WriteLine("========================");
}
}
}
string text = System.IO.File.ReadAllText(@"d:\release.zip\Readme.txt");
Console.WriteLine("Contents of WriteText.txt = {0}", text);
}
}
}
Run Code Online (Sandbox Code Playgroud)
zip文件及其条目均已创建,我可以从Windows资源管理器中访问它们,但是一旦代码尝试读取它,它将得到以下错误: …