C# 访问 zip 存档中的文本文件 [英] C# Access text file in zip archive

查看:29
本文介绍了C# 访问 zip 存档中的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何读取 zip 存档中文本文件的内容?

How can I read content of a text file inside a zip archive?

例如,我有一个存档 qwe.zip,并且在它里面有一个文件 asd.txt,那么我如何读取该文件的内容?

For example I have an archive qwe.zip, and insite it there's a file asd.txt, so how can I read contents of that file?

是否可以不提取整个档案?因为它需要快速完成,当用户单击列表中的一个项目时,显示存档的描述(它需要其他程序的插件系统).因此,提取整个存档并不是最好的解决方案……因为它可能只有几 Mb,这至少需要几秒钟甚至更长时间才能提取……而只需要读取单个文件.

Is it possible to do without extracting the whole archive? Because it need to be done quick, when user clicks a item in a list, to show description of the archive (it needed for plugin system for another program). So extracting a whole archive isn't the best solution... because it might be few Mb, which will take at least few seconds or even more to extract... while only that single file need to be read.

推荐答案

您可以使用一个库,例如 SharpZipLibDotNetZip 解压缩文件并获取其中包含的单个文件的内容.此操作可以在内存中执行,您不需要将文件存储到临时文件夹中.

You could use a library such as SharpZipLib or DotNetZip to unzip the file and fetch the contents of individual files contained inside. This operation could be performed in-memory and you don't need to store the files into a temporary folder.

这篇关于C# 访问 zip 存档中的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆