C# BinaryWriter Write(Char)

Description

BinaryWriter Write(Char) Writes a Unicode character to the current stream and advances the current position of the stream in accordance with the Encoding used and the specific characters being written to the stream.

Syntax

BinaryWriter.Write(Char) has the following syntax.


public virtual void Write(
  char ch
)

Parameters

BinaryWriter.Write(Char) has the following parameters.

  • ch - The non-surrogate, Unicode character to write.

Returns

BinaryWriter.Write(Char) method returns

Example

The following code example shows how to read and write data using memory as a backing store.


/*from   ww  w .j  a v a2s .  c  om*/
using System;
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i = 0;
        char[] invalidPathChars = new char[]{'a','b','c'};
        MemoryStream memStream = new MemoryStream();
        BinaryWriter binWriter = new BinaryWriter(memStream);

        for(i = 0; i < invalidPathChars.Length; i++)
        {
            binWriter.Write(invalidPathChars[i]);
        }

        BinaryReader binReader = new BinaryReader(memStream);

        memStream.Position = 0;

        Console.Write(binReader.ReadString());
        char[] memoryData = new char[memStream.Length - memStream.Position];
        for(i = 0; i < memoryData.Length; i++)
        {
            memoryData[i] = binReader.ReadChar();
        }
        Console.WriteLine(memoryData);
    }
}




















Home »
  C# Tutorial »
    System.IO »




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