C# BinaryReader ReadByte

Description

BinaryReader ReadByte Reads the next byte from the current stream and advances the current position of the stream by one byte.

Syntax

BinaryReader.ReadByte has the following syntax.


public virtual byte ReadByte()

Returns

BinaryReader.ReadByte method returns The next byte read from the current stream.

Example


//from w w w . j  ava 2  s  . co m
using System;
using System.IO;

class ConsoleApplication
{
    const string fileName = "data.dat";

    static void Main()
    {

        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
        {
            writer.Write((byte)123);
        }

        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            Console.WriteLine(reader.ReadByte());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter