File.OpenRead : File « System.IO « C# / C Sharp by API






File.OpenRead

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

class MainClass
{
  public static void Main() 
  {
    FileStream inStream = File.OpenRead("c:\\text.txt");
    FileStream outStream = File.OpenWrite("c:\\text.txt" + ".bak");

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

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

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

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

   
  








Related examples in the same category

1.File.CreateText(String fileName)
2.File.Delete
3.File.Exists(String fileName)
4.File.GetLastAccessTime
5.File.OpenText
6.File.OpenWrite
7.File.ReadAllLines(String fileName)
8.File.SetAccessControl
9.File.WriteAllLines(String fileName, String[] lines)