Byte-Oriented: Write to a file : Byte Read Write « File Stream « C# / C Sharp






Byte-Oriented: Write to a file

 

using System;
using System.IO;
class WriteToFile {
  public static void Main(string[] args) {
    FileStream fout;

    try {
      fout = new FileStream("test.txt", FileMode.Create);
    } catch(IOException exc) {
      Console.WriteLine(exc.Message + "\nError Opening Output File");
      return;
    }

    // Write the alphabet to the file.
    try {
      for(char c = 'A'; c <= 'Z'; c++)
        fout.WriteByte((byte) c);
    } catch(IOException exc) {
      Console.WriteLine(exc.Message + "File Error");
    }

    fout.Close();
  }
}
           
         
  








Related examples in the same category

1.Byte-Oriented File input and outputByte-Oriented File input and output
2.Save byte array to a file
3.Write byte array to a file
4.Compare two files byte by byte
5.Read file content to a byte array
6.Read binary context of a file.
7.Save a byte array content into a file.