C# BinaryWriter Write(Byte[]) Array

Description

BinaryWriter Write(Byte[]) Writes a byte array to the underlying stream.

Syntax

BinaryWriter.Write(Byte[]) has the following syntax.


public virtual void Write(
  byte[] buffer
)

Parameters

BinaryWriter.Write(Byte[]) has the following parameters.

  • buffer - A byte array containing the data to write.

Returns

BinaryWriter.Write(Byte[]) method returns

Example


using System;/*from  w w w.  j av  a2s . c  om*/
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(new 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