我有一个包含csv文件的zip文件。我使用以下代码来读取该文件:
using (ZipArchive zipArchive = ZipFile.OpenRead(filePath))
{
var zipArchiveEntry = zipArchive.GetEntry("File.csv");
var zipEntry = zipArchiveEntry.Open();
...
}zipEntry的类型为System.IO.Compreesion.Deflatestream。
我尝试使用StreamReader.CurrentEncoding,但它给出了错误的编码值。
我现在使用的是this解决方案,
this.GetFileEncoding(zipEntry)但是在fileStrem.Length上获取NotSupportedException。
如何找到正确的zipEntry编码(File.csv)?
发布于 2017-09-26 20:26:05
如果您可以确保该文件实际上是一个cvs文件,那么只需使用流读取器在打开时从条目的流中获取它的内容
using (ZipArchive archive = ZipFile.OpenRead(filePath)) {
var entry = archive.GetEntry("File.csv");
if (entry != null) {
using (var reader = new StreamReader(entry.Open())) {
var csv = reader.ReadToEnd();
}
}
} https://stackoverflow.com/questions/46425648
复制相似问题