Mega Code Archive

 
Categories / C# / File Stream
 

Copy Stream from fromStream to toStream

//     Copyright (c) Microsoft Corporation.  All rights reserved. // This file is best viewed using outline mode (Ctrl-M Ctrl-O) // // This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in. // It is available from http://www.codeplex.com/hyperAddin  //  using System; using System.IO;     class MainClass{         static public int CopyStream(Stream fromStream, Stream toStream)         {             byte[] buffer = new byte[8192];             int totalBytes = 0;             for (; ; )             {                 int count = fromStream.Read(buffer, 0, buffer.Length);                 if (count == 0)                     break;                 toStream.Write(buffer, 0, count);                 totalBytes += count;             }             return totalBytes;         }     }