1、引用 SharpCompress.dll
2、代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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:\ConsoleApplication1\ConsoleApplication1\rain.tgz"); Console.WriteLine("Decompress Succeed!"); Console.ReadLine(); } private static string directoryPath = @"E:\ConsoleApplication1\ConsoleApplication1\新建文件夹"; 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); } } } } } |
以上这篇C# 解压gizp文件(.tgz)的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://www.cnblogs.com/intro/archive/2017/12/26/8119035.html