Buffered IO with BufferedStream in CSharp

Description

The following code shows how to buffered IO with BufferedStream.

Example


    //from ww w.  j  a  v  a  2 s  .co  m


using System;
using System.IO;

    class Tester
    {
        

        public static void Main()
        {
            int SizeBuff = 1024;
            Stream inputStream = File.OpenRead("folder3.cs");
            Stream outputStream = File.OpenWrite("folder3.bak");
            BufferedStream bufferedInput = new BufferedStream(inputStream);
            BufferedStream bufferedOutput = new BufferedStream(outputStream);
            byte[] buffer = new Byte[SizeBuff];
            int bytesRead;

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




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip