- String sourcefilename = FILETOBECOMPRESSED;
- Filestream sourcefile = File.OpenRead(sourcefilename);
- Filestream destinationfile = File.Create(outputfilename);
- DeflateStream compressionstream = new DeflateStream(destinationfile, CompressionMode.Compress);
- int sourcebyte = sourcefile.ReadByte();
- while(sourcebyte != -1)
- {
- compressionstream.WriteByte((byte)sourcebyte);
- sourcebyte = sourcefile.ReadByte();
- }
- //该片段来自于http://www.codesnippet.cn/detail/220820135307.html
来源: http://www.codesnippet.cn/detail/220820135307.html