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






FileStream.Write

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

class MainClass
{
  public static void Main() 
  {
    FileStream inStream = File.OpenRead("C:\\test.txt");
    FileStream outStream = File.OpenWrite("C:\\test.txt" + ".bak");
    byte[] buf = new byte[4096];
    int bytesRead;

    while ((bytesRead = inStream.Read(buf, 0, 4096)) > 0)
      outStream.Write(buf, 0, bytesRead);

    outStream.Flush();
    outStream.Close();
    inStream.Close();

  }
}

   
  








Related examples in the same category

1.new FileStream(String fileName, FileMode.Open)
2.new FileStream("soaptest.xml", FileMode.Create, FileAccess.ReadWrite)
3.FileStream.Position
4.FileStream.Read
5.FileStream.ReadByte
6.FileStream.SetLength
7.FileStream.WriteByte