SharpZipLib解压文件
使用SharpZipLib解压文件。
void UnZip(string zipFile, string tagetDirectory) { if (!File.Exists(zipFile)) return; using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFile))) { ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { string entryName = theEntry.Name; var entryPath = Path.Combine(tagetDirectory, entryName); string directoryName = Path.GetDirectoryName(entryPath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (!theEntry.IsFile) { continue; } using (FileStream streamWriter = File.Create(entryPath)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } } } } }
Categories:
.net
Tags:
code
已禁用评论。