当前位置: 移动技术网 > IT编程>开发语言>c# > C#实现解压GZip文件的方法

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

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网