C# BinaryReader BinaryReader(Stream, Encoding)

Description

BinaryReader BinaryReader(Stream, Encoding) Initializes a new instance of the BinaryReader class based on the specified stream and character encoding.

Syntax

BinaryReader.BinaryReader(Stream, Encoding) has the following syntax.


public BinaryReader(
  Stream input,
  Encoding encoding
)

Parameters

BinaryReader.BinaryReader(Stream, Encoding) has the following parameters.

  • input - The input stream.
  • encoding - The character encoding to use.

Example


/*from ww w. j  a v  a  2 s.  c o  m*/
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)))
        {
            writer.Write(1.250F);
            writer.Write(@"c:\Temp");
            writer.Write(10);
            writer.Write(true);
        }
        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open),System.Text.Encoding.ASCII))
        {
            Console.WriteLine(reader.ReadSingle());
        }
    }
}

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