C# 解壓縮文件
阿新 • • 發佈:2017-12-29
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# 解壓縮文件