C# BinaryReader ReadString

Description

BinaryReader ReadString Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.

Syntax

BinaryReader.ReadString has the following syntax.


public virtual string ReadString()

Returns

BinaryReader.ReadString method returns The string being read.

Example


using System;/*from w w  w . j  a v  a 2 s .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("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