C# BinaryReader BinaryReader(Stream)

Description

BinaryReader BinaryReader(Stream) Initializes a new instance of the BinaryReader class based on the specified stream and using UTF-8 encoding.

Syntax

BinaryReader.BinaryReader(Stream) has the following syntax.


public BinaryReader(
  Stream input
)

Parameters

BinaryReader.BinaryReader(Stream) has the following parameters.

  • input - The input stream.

Example

The following code example demonstrates how to store and retrieve application settings in a file.


//  w ww  . jav a  2s . 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)))
        {
            writer.Write(1.250F);
            writer.Write(@"c:\Temp");
            writer.Write(10);
            writer.Write(true);
        }
        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            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