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.Flush() // you must flush a buffered output !!


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s