C#實現解壓GZip文件的方法
更新時間:2015年05月15日 12:15:49 作者:皮蛋
這篇文章主要介紹了C#實現解壓GZip文件的方法,涉及C#操作壓縮文件的技巧,需要的朋友可以參考下
本文實例講述了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#如何動態(tài)創(chuàng)建lambda表達式
這篇文章主要介紹了C#如何動態(tài)創(chuàng)建lambda表達式問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02C#中Request.Cookies 和 Response.Cookies 的區(qū)別分析
本文通過實例代碼向我們展示了C#中Request.Cookies 和 Response.Cookies 的區(qū)別,文章淺顯易懂,這里推薦給大家。2014-11-11使用linq to xml修改app.config示例(linq讀取xml)
這篇文章主要介紹了使用linq to xml修改app.config示例,需要的朋友可以參考下2014-02-02C#開發(fā)Android百度地圖手機應用程序(多地圖展示)
這篇文章主要介紹了C#開發(fā)Android百度地圖手機應用程序(多地圖展示)的相關資料,需要的朋友可以參考下2016-02-02