C# BinaryWriter BaseStream

Description

BinaryWriter BaseStream Gets the underlying stream of the BinaryWriter.

Syntax

BinaryWriter.BaseStream has the following syntax.


public virtual Stream BaseStream { get; }

Example

Gets the underlying stream of the BinaryWriter.


using System;/* w  w w.j  a  v  a2 s.c  o m*/
using System.IO;

class BinaryRW
{
    static void Main()
    {
        using(BinaryWriter binWriter = new BinaryWriter(new MemoryStream()))
        {
            int i;
            const int arrayLength = 1000;
            double[] dataArray = new double[arrayLength];
            for(i = 0; i < arrayLength; i++)
            {
                dataArray[i] = 100.1 * i;
            }

            for(i = 0; i < arrayLength; i++)
            {
                binWriter.Write(dataArray[i]);
            }
            using(BinaryReader binReader = new BinaryReader(binWriter.BaseStream))
            {
                binReader.BaseStream.Position = 0;
                for(i = 0; i < arrayLength; i++)
                {
                    if(binReader.ReadDouble() != dataArray[i])
                    {
                        Console.WriteLine("Error writing data.");
                        break;
                    }
                }
            }
        }
    }
}




















Home »
  C# Tutorial »
    System.IO »




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