日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#System.IO.Compression命名空間

C# System.IO.Compression命名空間,注意:此命名空間在 .NET Framework 2.0 版中是新增的。C# System.IO.Compression命名空間包含提供基本的流壓縮和解壓縮服務(wù)的類。GZipStream提供用于壓縮和解壓縮流的方法和屬性。下面以 GZipStream  為例說明

創(chuàng)新互聯(lián)是一家專業(yè)提供烏拉特中企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計、成都做網(wǎng)站、H5場景定制、小程序制作等業(yè)務(wù)。10年已為烏拉特中眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。

注意:此類在 .NET Framework 2.0 版中是新增的。

提供用于壓縮和解壓縮流的方法和屬性。
命名空間:System.IO.Compression
程序集:System(在 system.dll 中)
語法
Visual Basic(聲明)
Public Class GZipStream
Inherits Stream
Visual Basic(用法)
Dim instance As GZipStream

C#
public class GZipStream : Stream

C++
public ref class GZipStream : public Stream

J#
public class GZipStream extends Stream

JScript
public class GZipStream extends Stream

 
 
 
  1. classclsZip
  2. ...{
  3. publicvoidCompressFile(stringsourceFile,stringdestinationFile)
  4. ...{
  5. //makesurethesourcefileisthere
  6. if(File.Exists(sourceFile)==false)
  7. thrownewFileNotFoundException();
  8. //Createthestreamsandbytearraysneeded
  9. byte[]buffer=null;
  10. FileStreamsourceStream=null;
  11. FileStreamdestinationStream=null;
  12. GZipStreamcompressedStream=null;
  13. try
  14. ...{
  15. //Readthebytesfromthesourcefileintoabytearray
  16. sourceStream=newFileStream(sourceFile,FileMode.Open,FileAccess.Read,FileShare.Read);
  17. //Readthesourcestreamvaluesintothebuffer
  18. buffer=newbyte[sourceStream.Length];
  19. intcheckCounter=sourceStream.Read(buffer,0,buffer.Length);
  20. if(checkCounter!=buffer.Length)
  21. ...{
  22. thrownewApplicationException();
  23. }
  24. //OpentheFileStreamtowriteto
  25. destinationStream=newFileStream(destinationFile,FileMode.OpenOrCreate,FileAccess.Write);
  26. //Createacompressionstreampointingtothedestiantionstream
  27. compressedStream=newGZipStream(destinationStream,CompressionMode.Compress,true);
  28. //Nowwritethecompresseddatatothedestinationfile
  29. compressedStream.Write(buffer,0,buffer.Length);
  30. }
  31. catch(ApplicationExceptionex)
  32. ...{
  33. MessageBox.Show(ex.Message,"壓縮文件時發(fā)生錯誤:",MessageBoxButtons.OK,MessageBoxIcon.Error);
  34. }
  35. finally
  36. ...{
  37. //Makesureweallwayscloseallstreams
  38. if(sourceStream!=null)
  39. sourceStream.Close();
  40. if(compressedStream!=null)
  41. compressedStream.Close();
  42. if(destinationStream!=null)
  43. destinationStream.Close();
  44. }
  45. }
  46. publicvoidDecompressFile(stringsourceFile,stringdestinationFile)
  47. ...{
  48. //makesurethesourcefileisthere
  49. if(File.Exists(sourceFile)==false)
  50. thrownewFileNotFoundException();
  51. //Createthestreamsandbytearraysneeded
  52. FileStreamsourceStream=null;
  53. FileStreamdestinationStream=null;
  54. GZipStreamdecompressedStream=null;
  55. byte[]quartetBuffer=null;
  56. try
  57. ...{
  58. //Readinthecompressedsourcestream
  59. sourceStream=newFileStream(sourceFile,FileMode.Open);
  60. //Createacompressionstreampointingtothedestiantionstream
  61. decompressedStream=newGZipStream(sourceStream,CompressionMode.Decompress,true);
  62. //Readthefootertodeterminethelengthofthedestiantionfile
  63. quartetBuffer=newbyte[4];
  64. intposition=(int)sourceStream.Length-4;
  65. sourceStream.Position=position;
  66. sourceStream.Read(quartetBuffer,0,4);
  67. sourceStream.Position=0;
  68. intcheckLength=BitConverter.ToInt32(quartetBuffer,0);
  69. byte[]buffer=newbyte[checkLength+100];
  70. intoffset=0;
  71. inttotal=0;
  72. //Readthecompresseddataintothebuffer
  73. while(true)
  74. ...{
  75. intbytesRead=decompressedStream.Read(buffer,offset,100);
  76. if(bytesRead==0)
  77. break;
  78. offset+=bytesRead;
  79. total+=bytesRead;
  80. }
  81. //Nowwriteeverythingtothedestinationfile
  82. destinationStream=newFileStream(destinationFile,FileMode.Create);
  83. destinationStream.Write(buffer,0,total);
  84. //andflusheveryhtingtocleanoutthebuffer
  85. destinationStream.Flush();
  86. }
  87. catch(ApplicationExceptionex)
  88. ...{
  89. MessageBox.Show(ex.Message,"解壓文件時發(fā)生錯誤:",
    MessageBoxButtons.OK,MessageBoxIcon.Error);
  90. }
  91. finally
  92. ...{
  93. //Makesureweallwayscloseallstreams
  94. if(sourceStream!=null)
  95. sourceStream.Close();
  96. if(decompressedStream!=null)
  97. decompressedStream.Close();
  98. if(destinationStream!=null)
  99. destinationStream.Close();
  100. }
  101. }
  102. }

以上介紹C# System.IO.Compression命名空間


文章題目:C#System.IO.Compression命名空間
文章位置:http://www.5511xx.com/article/ccoopge.html