C#实现解压GZip文件的方法

作者:皮蛋 时间:2022-11-29 07:25:36 

本文实例讲述了C#实现解压GZip文件的方法。分享给大家供大家参考。具体实现方法如下:


public void ungzip(string path, string decomPath, bool overwrite)
{
 //for overwriting purposes
 if (File.Exists(decomPath))
 {
if (overwrite)
{
  File.Delete(decomPath);
}
else
{
  throw new IOException("The decompressed path you specified already exists and cannot be overwritten.");
}
 }
 //create our file streams
 GZipStream stream = new GZipStream(new FileStream(path, FileMode.Open, FileAccess.ReadWrite), CompressionMode.Decompress);
 FileStream decompressedFile = new FileStream(decomPath, FileMode.OpenOrCreate, FileAccess.Write);
 //data represents a byte from the compressed file
 //it's set through each iteration of the while loop
 int data;
 while ((data = stream.ReadByte()) != -1) //iterates over the data of the compressed file and writes the decompressed data
 {
decompressedFile.WriteByte((byte)data);
 }
 //close our file streams
 decompressedFile.Close();
 stream.Close();
}

希望本文所述对大家的C#程序设计有所帮助。

标签:C#,解压
0
投稿

猜你喜欢

  • Java中缀表达式转后缀表达式实现方法详解

    2021-08-25 02:57:20
  • c# 将Minio.exe注册成windows服务

    2022-09-25 20:51:18
  • mybatis trim标签的使用详解

    2022-07-10 23:27:54
  • Android 存储路径选择方法

    2022-04-03 21:05:42
  • Java SE求解汉诺塔问题的示例代码

    2022-05-10 23:44:30
  • c# WPF实现Windows资源管理器(附源码)

    2022-10-01 14:34:46
  • java获取注册ip实例

    2023-11-03 23:01:12
  • Java如何从json字符串中获取某个值详解

    2023-11-18 12:18:12
  • Android Jetpack中Room的使用

    2021-11-11 08:43:36
  • Android自定义View新年烟花、祝福语横幅动画

    2022-01-24 21:31:27
  • Java中EnvironmentAware 接口的作用

    2023-04-15 16:11:12
  • Android序列化接口Parcelable与Serializable接口对比

    2023-03-24 17:48:59
  • Android 保存WebView中的图片示例

    2021-10-05 21:57:05
  • RollViewPager图片轮播效果开源框架使用方法详解

    2021-12-06 07:22:59
  • Android自定义View实现带4圆角或者2圆角的效果

    2023-04-08 04:32:10
  • 在C#中global关键字的作用及其用法

    2021-12-24 04:33:19
  • 一场由Java中Integer引发的踩坑实战

    2021-09-06 11:14:40
  • JAVA技术实现上传下载文件到FTP服务器(完整)

    2023-08-26 15:35:43
  • Java常用集合与原理解析

    2023-04-01 14:26:42
  • Java中实现文件预览的功能(实例代码)

    2023-09-09 16:13:06
  • asp之家 软件编程 m.aspxhome.com