C# BinaryWriter Write(Char[], Int32, Int32)

Description

BinaryWriter Write(Char[], Int32, Int32) Writes a section of a character array to the current stream, and advances the current position of the stream in accordance with the Encoding used and perhaps the specific characters being written to the stream.

Syntax

BinaryWriter.Write(Char[], Int32, Int32) has the following syntax.


public virtual void Write(
  char[] chars,/*  w w  w  .j  a  v  a 2  s .c o  m*/
  int index,
  int count
)

Parameters

BinaryWriter.Write(Char[], Int32, Int32) has the following parameters.

  • chars - A character array containing the data to write.
  • index - The starting point in chars from which to begin writing.
  • count - The number of characters to write.

Returns

BinaryWriter.Write(Char[], Int32, Int32) method returns

Example


/*from   w  w  w.j a  v a 2 s. c om*/
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)))
        {
            char[] chars = new char[]{'a','v','c','d'};
            writer.Write(chars,0,2);
        }
        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            Console.WriteLine(reader.ReadInt32());
        }
    }
}




















Home »
  C# Tutorial »
    System.IO »




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