C# BinaryWriter Write(String)

Description

BinaryWriter Write(String) Writes a length-prefixed string to this stream in the current encoding of the BinaryWriter, 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(String) has the following syntax.


public virtual void Write(
  string value
)

Parameters

BinaryWriter.Write(String) has the following parameters.

  • value - The value to write.

Returns

BinaryWriter.Write(String) method returns

Example


using System;//from   w ww.j ava2 s  . 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("java2s.com");
        }
        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            Console.WriteLine(reader.ReadString());
        }
    }
}

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