Binary Writer Reader : BinaryWriter « File Directory Stream « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

  class Program
  {
    static void Main(string[] args)
    {
      FileInfo f = new FileInfo("BinFile.dat");
      using (BinaryWriter bw = new BinaryWriter(f.OpenWrite()))
      {
        double aDouble = 1234.67;
        int anInt = 34567;
        string aString = "A, B, C";
        bw.Write(aDouble);
        bw.Write(anInt);
        bw.Write(aString);
      }
      using (BinaryReader br = new BinaryReader(f.OpenRead()))
      {
        Console.WriteLine(br.ReadDouble());
        Console.WriteLine(br.ReadInt32());
        Console.WriteLine(br.ReadString());
      }
    }
  }








15.27.BinaryWriter
15.27.1.Commonly Used Output Methods Defined by BinaryWriter
15.27.2.Write and read back binary data
15.27.3.Write decimal, strings and char to a file using the BinaryWriter
15.27.4.Move internal position for a BinaryWriter
15.27.5.Write/Read int, float, char array and bool to a binary file using BinaryWriter
15.27.6.Use BinaryWriter to save data in binary format
15.27.7.Binary Writer Reader