C#实现解压GZip文件的方法
程序员文章站
2022-07-01 17:25:40
本文实例讲述了c#实现解压gzip文件的方法。分享给大家供大家参考。具体实现方法如下:
public void ungzip(string path, strin...
本文实例讲述了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#程序设计有所帮助。
上一篇: 针灸能根治前列腺炎吗 针灸治疗效果怎么样
下一篇: 针灸减肥期间宜食用的6款食谱