BufferedStream.Write : BufferedStream « System.IO « C# / C Sharp by API






BufferedStream.Write

 

using System;
using System.Windows.Forms;
using System.IO;

public class MainClass 
{
  public static void Main() 
  {
    OpenFileDialog dlgOpen = new OpenFileDialog();
    dlgOpen.Title="Select file to back up";
    if (dlgOpen.ShowDialog() == DialogResult.OK)
    {
      FileStream inStream = File.OpenRead(dlgOpen.FileName);
      FileStream outStream = File.OpenWrite(dlgOpen.FileName + ".bak");

      BufferedStream bufInStream = new BufferedStream(inStream);
      BufferedStream bufOutStream = new BufferedStream(outStream);

      byte[] buf = new byte[4096];
      int bytesRead;

      while ((bytesRead = bufInStream.Read(buf, 0, 4096)) > 0)
        bufOutStream.Write(buf, 0, bytesRead);

      bufOutStream.Flush();
      bufOutStream.Close();
      bufInStream.Close();
      outStream.Close();
      inStream.Close();
    }
  }
}

   
  








Related examples in the same category

1.new BufferedStream(FileStream fs)
2.BufferedStream.Position
3.BufferedStream.Read
4.BufferedStream.WriteByte