一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

C# 解压gizp文件(.tgz)的实例

时间:2022-06-25 07:45:01 编辑:袖梨 来源:一聚教程网

1、引用 SharpCompress.dll

2、代码

using System;
using System.IO;
using System.Text;
using SharpCompress.Reader;
using SharpCompress.Common;
namespace ConsoleApplication1
{
 class Program
 {
 static void Main(string[] args)
 {
  unTAR(@"E:ConsoleApplication1ConsoleApplication1rain.tgz");
  Console.WriteLine("Decompress Succeed!");
  Console.ReadLine();
 }
 private static string directoryPath = @"E:ConsoleApplication1ConsoleApplication1新建文件夹";
 static void unTAR(string tarFilePath)
 {
  // UTF7: support chinese font -> UTF.7
  SharpCompress.Common.ArchiveEncoding.Default = Encoding.UTF7;
  using (Stream stream = File.OpenRead(tarFilePath))
  {
  var reader = ReaderFactory.Open(stream);
  while (reader.MoveToNextEntry())
  {
   if (!reader.Entry.IsDirectory)
   reader.WriteEntryToDirectory(directoryPath,
    ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
  }
  }
 }
 }
}

热门栏目