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






FileStream.ReadByte

 

using System;
using System.IO;

class ShowFile {
  public static void Main(string[] args) {
    int i;
    FileStream fin;

    try {
      fin = new FileStream("test.cs", FileMode.Open);
    } catch(FileNotFoundException exc) {
      Console.WriteLine(exc.Message);
      return;
    } catch(IndexOutOfRangeException exc) {
      Console.WriteLine(exc.Message + "\nUsage: ShowFile File");
      return;
    }

    // read bytes until EOF is encountered
    do {
      try {
        i = fin.ReadByte();
      } catch(Exception exc) {
        Console.WriteLine(exc.Message);
        return;
      }
      if(i != -1) Console.Write((char) i);
    } while(i != -1);

    fin.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.SetLength
6.FileStream.Write
7.FileStream.WriteByte