欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#使用DeflateStream解壓縮數(shù)據(jù)文件的方法

 更新時間:2015年04月13日 08:59:40   作者:令狐不聰  
這篇文章主要介紹了C#使用DeflateStream解壓縮數(shù)據(jù)文件的方法,較為詳細(xì)的分析了DeflateStream方法對文件進(jìn)行壓縮及解壓縮的步驟與技巧,需要的朋友可以參考下

本文實例講述了C#使用DeflateStream解壓縮數(shù)據(jù)文件的方法。分享給大家供大家參考。具體分析如下:

DeflateStream方法用于從一個流中讀取數(shù)據(jù),并寫入到另一個流。DeflateStream不寫入數(shù)據(jù)到其它類型的資源,比如文件或者內(nèi)存。 DeflateStream在寫入另一個流的時候,它會對數(shù)據(jù)進(jìn)行壓縮和解壓縮。

使用DEFLATE壓縮數(shù)據(jù)文件的一般過程:

打開一個現(xiàn)有的文件 
打開/創(chuàng)建輸出文件 
創(chuàng)建減縮對象 
逐字節(jié)讀取源文件,并把它傳遞給DEFLATE對象 
使用deflate對象寫入輸出文件流

String sourcefilename = FILETOBEUNCOMPRESSED;
Filestream sourcefile = File.OpenRead(sourcefilename);
Filestream destinationfile = File.Create(outputfilename);
DeflateStream compressionstream = new DeflateStream(sourcefile,CompressionMode.Decompress);
int sourcebyte = compressionstream.ReadByte();
while(sourcebyte != -1)
{
  destinationfile.WriteByte((byte)sourcebyte);
  sourcebyte = compressionstream.ReadByte();
}

希望本文所述對大家的C#程序設(shè)計有所幫助。

相關(guān)文章

最新評論