C# BinaryWriter Write(Byte)

Description

BinaryWriter Write(Byte) Writes an unsigned byte to the current stream and advances the stream position by one byte.

Syntax

BinaryWriter.Write(Byte) has the following syntax.


public virtual void Write(
  byte value
)

Parameters

BinaryWriter.Write(Byte) has the following parameters.

  • value - The unsigned byte to write.

Returns

BinaryWriter.Write(Byte) method returns

Example


using System;//from  w ww. j a  v a  2s.co  m
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