C#实现Zip文件解压
首先需要安装7-Zip。7-Zip是一款高压缩比的压缩软件,不仅支持独有的7z文件格式,而且还支持各种其它压缩文件格式,其中包括 ZIP、RAR、CAB、GZIP、BZIP2和TAR等格式。此软件压缩的压缩比要比普通ZIP文件高30-50%。
方式一:
/// <summary>
/// 解压Zip文件
/// </summary>
public static void Unzip()
{string zipFileName = @"E:\MyZip\Report.zip"; //需要被解压的Zip文件string unZipPath = @"E:\MyZip\"; //解压后文件存放目录string pwd = "123"; //解压密码Process process = new Process();process.StartInfo.FileName = @"C:\Program Files\7-Zip\7z.exe"; //7-Zip工具的运行程序process.StartInfo.Arguments = String.Format("e \"{0}\" -p{1} -o\"{2}\"", zipFileName, pwd, unZipPath);process.Start();
}
方式二:
创建ProcessHelper.cs类。
public class ProcessHelper
{public static string[] ExecCommand(string commands){//msg[0]执行结果;msg[1]错误结果string[] msg = new string[2];Process proc = new Process();try{proc.StartInfo.FileName = "cmd.exe";proc.StartInfo.UseShellExecute = false;proc.StartInfo.RedirectStandardInput = true;proc.StartInfo.RedirectStandardOutput = true;proc.StartInfo.RedirectStandardError = true;proc.StartInfo.CreateNoWindow = true;proc.Start();proc.StandardInput.WriteLine(commands);proc.StandardInput.WriteLine("exit");//执行结果msg[0] = proc.StandardOutput.ReadToEnd();proc.StandardOutput.Close();//出错结果msg[1] = proc.StandardError.ReadToEnd();proc.StandardError.Close();//超时等待int maxWaitCount = 10;while (proc.HasExited == false && maxWaitCount > 0){proc.WaitForExit(1000);maxWaitCount--;}if (maxWaitCount == 0){msg[1] = "操作执行超时";proc.Kill();}return msg;}catch (Exception ex){msg[1] = "进程创建失败:";msg[1] += ex.Message.ToString();msg[1] += ex.StackTrace.ToString();}finally{proc.Close();proc.Dispose();}return msg;}
}
调用方法:
/// <summary>
/// 解压Zip文件
/// </summary>
public static void Unzip()
{string zipExe = @"C:\Program Files\7-Zip\7z.exe"; //7-Zip工具的运行程序string zipFileName = @"E:\MyZip\Report.zip"; //需要被解压的Zip文件string unZipPath = @"E:\MyZip\"; //解压后文件存放目录string pwd = "123"; //解压密码//执行解压命令string cmd = String.Format("\"{0}\" e \"{1}\" -p{2} -o\"{3}\"", zipExe, zipFileName, pwd, unZipPath);ProcessHelper.ExecCommand(cmd);
}
C#实现Zip文件解压相关推荐
- Java实现Zip文件解压
2019独角兽企业重金招聘Python工程师标准>>> ##1. 两种java实现zip文件解压方式 使用JDK的原生类java.util.zip,上代码: import java. ...
- [转载] python zip 文件解压中文乱码问题解决
参考链接: Python zip() 今天突然碰到zip文件解压后中文乱码问题.百度了下觉得这篇文章不错.保存保存. 来源:http://blog.sina.com.cn/s/blog_5805e98 ...
- 解压文件到服务器是什么意思,linux中zip文件解压命令是什么
linux中zip文件解压命令是什么 发布时间:2020-10-15 14:35:15 来源:亿速云 阅读:102 作者:小新 这篇文章给大家分享的是有关linux中zip文件解压命令是什么的内容.小 ...
- android zip文件读写,【Android】Zip文件解压方法
android中zip文件解压 public class ZipUtil { /** * 解压到指定路径 * * @param inputStream * @param outPathString * ...
- C++实现解zip解压缩功能:将一个目录内的内容打包到zip文件以及将zip文件解压到某个目录(windows平台)
本例用来简单实现windows平台下如何将一个目录下的文件压缩到指定的zip文件中,亦或是将一个zip文件的内容解压缩到某个目录. 以下是源码,代码中的注释解释了相关操作,一看就懂. 注: 本例将这两 ...
- linux 解压文件乱码,云服务器:解决linux下zip文件解压乱码问题
云服务器:解决linux下zip文件解压乱码问题 原因 由于zip格式并没有指定编码格式,Windows下生成的zip文件中的编码是GBK/GB2312等,因此,导致这些zip文件在Linux下解压时 ...
- linux php 压缩中文乱码,linux下zip文件解压乱码问题的解决办法分享
本篇文章主要介绍了解决linux下zip文件解压乱码问题,具有一定的参考价值,感兴趣的小伙伴们可以参考一下. 原因 由于zip格式并没有指定编码格式,Windows下生成的zip文件中的编码是GBK/ ...
- linux中zip文件编码错误,解决linux下zip文件解压乱码问题
原标题:解决linux下zip文件解压乱码问题 解决linux下zip文件解压乱码问题 原因 由于zip格式并没有指定编码格式,Windows下生成的zip文件中的编码是GBK/GB2312等,因此, ...
- linux中zip文件解压命令,Linux中zip压缩和unzip解压缩命令使用方法
Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统.在Linux中,我们可以利用命令进行文件压缩,即zip压缩和unzip解压缩,这篇文章主要介绍了详解Linux中zi ...
- java zip文件解压(含有密码解压)
maven需要加入以下依赖: <dependency><groupId>net.lingala.zip4j</groupId><artifactId>z ...
最新文章
- 纯JS导出excel(支持中文)
- LeetCode K-diff Pairs in an Array
- web开发的发展历史
- java ArrayList源码分析(转载)
- Android开发学习之卡片式布局的简单实现
- beanstalkd mysql_beanstalkd 安装和配置
- 深入解读Linux进程调度系列(1)——调度的初始化
- [R语言绘图]plot函数的使用
- matlab数字图像处理常用操作
- html链接鼠标在悬停颜色,如何让HTML链接显示悬停样式?
- android toast显示在中间,android Toast 弹出在屏幕中间位置以及自定义Toast
- python 服务器后台运行
- 三维坐标系旋转——旋转矩阵到旋转角之间的换算
- 社科院与杜兰大学金融管理硕士——在自己的领域努力拼搏,终将遇到专属的光芒
- windows, macos 和 linux 各平台的哈希校验方法汇总
- Codeforces Round #362 (Div. 2) E. PLEASE(数论 + 递推)
- 电子邮件链接格式html主题,html创建电子邮件链接的方法
- MATLAB浮点数详解
- 属性动画Android动画,Android动画(三)属性动画Animator与Interpolator
- strsep 是将字符串截断