Chr*_*tow 33
DotNetZip - .NET语言中的Zip文件操作
DotNetZip是一个易于使用的小型类库,用于处理.zip文件.它可以使用VB.NET,C#(任何.NET语言)编写的.NET应用程序轻松创建,读取和更新zip文件.
用于读取zip的示例代码:
using (var zip = ZipFile.Read(PathToZipFolder))
{
int totalEntries = zip.Entries.Count;
foreach (ZipEntry e in zip.Entries)
{
e.FileName ...
e.CompressedSize ...
e.LastModified...
}
}
Run Code Online (Sandbox Code Playgroud)
Csa*_*oth 27
.NET 4.5或更新版本最终具有内置功能来处理类的通用zip文件System.IO.Compression.ZipArchive(http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110% 29.aspx)在程序集System.IO.Compression中.不需要任何第三方库.
string zipPath = @"c:\example\start.zip";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
Console.WriteLine(entry.FullName);
}
}
Run Code Online (Sandbox Code Playgroud)
Adr*_*ark 21
如果您使用的是.Net Framework 3.0或更高版本,请查看System.IO.Packaging命名空间.这将删除您对外部库的依赖性.
具体来看看ZipPackage类.
Chr*_*nce 12
ZipInputStream inStream = new ZipInputStream(File.OpenRead(fileName));
while (inStream.GetNextEntry())
{
ZipEntry entry = inStream.GetNextEntry();
//write out your entry's filename
}
Run Code Online (Sandbox Code Playgroud)
Ick - 使用J#运行时的代码很可怕!而且我不同意这是最好的方式 - 现在J#已经失去了支持.如果你想要的只是ZIP支持,它是一个巨大的运行时.
怎么样 - 它使用DotNetZip(免费,MS-Public许可证)
using (ZipFile zip = ZipFile.Read(zipfile) )
{
bool header = true;
foreach (ZipEntry e in zip)
{
if (header)
{
System.Console.WriteLine("Zipfile: {0}", zip.Name);
if ((zip.Comment != null) && (zip.Comment != ""))
System.Console.WriteLine("Comment: {0}", zip.Comment);
System.Console.WriteLine("\n{1,-22} {2,9} {3,5} {4,9} {5,3} {6,8} {0}",
"Filename", "Modified", "Size", "Ratio", "Packed", "pw?", "CRC");
System.Console.WriteLine(new System.String('-', 80));
header = false;
}
System.Console.WriteLine("{1,-22} {2,9} {3,5:F0}% {4,9} {5,3} {6:X8} {0}",
e.FileName,
e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
e.UncompressedSize,
e.CompressionRatio,
e.CompressedSize,
(e.UsesEncryption) ? "Y" : "N",
e.Crc32);
if ((e.Comment != null) && (e.Comment != ""))
System.Console.WriteLine(" Comment: {0}", e.Comment);
}
}
Run Code Online (Sandbox Code Playgroud)