本文实例讲述了c#使用deflatestream解压缩数据文件的方法。分享给大家供大家参考。具体分析如下:
deflatestream方法用于从一个流中读取数据,并写入到另一个流。deflatestream不写入数据到其它类型的资源,比如文件或者内存。 deflatestream在写入另一个流的时候,它会对数据进行压缩和解压缩。
使用deflate压缩数据文件的一般过程:
打开一个现有的文件
打开/创建输出文件
创建减缩对象
逐字节读取源文件,并把它传递给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#程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论