Reading and Writing Data – C# – part 2 (Buffered Streams)

Buffered Streams

Stream inputStream = File.OpenRead(@"C:\test\someFile.cs");
Stream outputStream = File.OpenWrite(@"C:\test\someOtherFile.cs");

BufferedStream bufferedInput = new BufferedStream(inputStream);
BufferedStream bufferedOutput = new BufferedStream(outputStream);

byte[] buffer = new Byte[SizeBuff];
int bytesRead;

while ( (bytesRead = bufferedInput.Read(buffer,0,SIZE_BUFF)) > 0 )
{
   bufferedOutput.Write(buffer,0,bytesRead);
}

bufferedOutput.Flush() // you must flush a buffered output !!
bufferedInput.Close()
bufferedOutput.Close()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s