BinaryWriter and BinaryReader classes for the writing and reading of primitive types : Binary Read Write « File Stream « C# / C Sharp






BinaryWriter and BinaryReader classes for the writing and reading of primitive types

BinaryWriter and BinaryReader classes for the writing and reading of primitive types
  

using System;
using System.IO;

public class Binary {
  public static void Main(string [] args) {
    BinaryWriter output = new BinaryWriter(new FileStream("test.dat",FileMode.Create));
    
    output.Write(1);
    
    output.Write(0.01);
   
    output.Close();
    BinaryReader input = new BinaryReader(new FileStream("test.dat",FileMode.Open));
    Console.WriteLine("{0} ", input.ReadInt32());
    Console.WriteLine("{0:F1} ", input.ReadDouble());
    input.Close();
  }
}


           
         
    
  








Related examples in the same category

1.Binary Writer Reader
2.new BinaryReader(stream)
3.StreamWriter and BinaryWriter
4.new BinaryWriter(stream) and Write method
5.Creating a sequential-access file
6.Reading a sequential-access fileReading a sequential-access file
7.Working with the BinaryWriter Class
8.Working with the BinaryReader ClassWorking with the BinaryReader Class
9.File pointer move and read binary file
10.Write and then read back binary dataWrite and then read back binary data
11.Use BinaryReader and BinaryWriter to implement a simple inventory programUse BinaryReader and BinaryWriter to implement 
   a simple inventory program
12.Read the data from a file and desiralize it
13.Read and Write a Binary File
14.Read Struct out of a file with BinaryReader
15.extends BinaryReader
16.Write a value at a given position. Used to write a size of data in an earlier located header.