1. 程式人生 > >C# 解壓縮文件

C# 解壓縮文件

c# while mod 文件 解壓縮 isp compress class sre

壓縮文件

技術分享圖片
public void YaSuo()
        {
            using (FileStream fsRead = File.OpenRead(@"F:\MVC5_Demo\Project4YaSuo\Project4YaSuo\Files\筆記.txt"))
            {
                //創建寫入文件的流
                using (FileStream fsWrite = File.OpenWrite(@"F:\MVC5_Demo\Project4YaSuo\Project4YaSuo\Files\yasuo.rar
")) { //創建壓縮流 using (GZipStream zipStream = new GZipStream(fsWrite, CompressionMode.Compress)) { //每次讀取1024byte byte[] byts = new byte[1024 * 10]; int len = 0;
while ((len = fsRead.Read(byts, 0, byts.Length)) > 0) { zipStream.Write(byts, 0, len);//通過壓縮流寫入文件 } } } } }
壓縮文件

解壓文件

技術分享圖片
public void JieYa()
        {
            //讀取壓縮文件
using (FileStream fsRead = File.OpenRead(@"F:\MVC5_Demo\Project4YaSuo\Project4YaSuo\Files\yasuo.rar")) { //創建壓縮流 using (GZipStream gzipStream = new GZipStream(fsRead, CompressionMode.Decompress)) { using (FileStream fsWrite = File.OpenWrite(@"F:\MVC5_Demo\Project4YaSuo\Project4YaSuo\Files\筆記.txt")) { byte[] byts = new byte[1024 * 10]; int len = 0; //寫入新文件 while ((len = gzipStream.Read(byts, 0, byts.Length)) > 0) { fsWrite.Write(byts, 0, len); } } } } }
解壓文件

C# 解壓縮文件