Working with the BinaryReader Class : Binary Read Write : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » Binary Read Write »

 

Working with the BinaryReader Class









    

using System;
using System.IO;
   
class MainClass {
    static public void Main() {
        FileStream    BinaryFile = new FileStream("test.dat", FileMode.Create, FileAccess.ReadWrite);
        BinaryReader  Reader = new BinaryReader(BinaryFile);
        BinaryWriter  Writer = new BinaryWriter(BinaryFile);
        
        Writer.Write('a');
        Writer.Write(123);
        Writer.Write(456.789);
        Writer.Write("test string");

        char   ReadCharacter;
        double ReadDouble;
        int    ReadInteger;
        string ReadString;
        
        BinaryFile.Seek(0, SeekOrigin.Begin);
        ReadCharacter = Reader.ReadChar();
        ReadInteger = Reader.ReadInt32();
        ReadDouble = Reader.ReadDouble();
        ReadString = Reader.ReadString();
   
        Console.WriteLine("Character: {0}", ReadCharacter);
        Console.WriteLine("Integer: {0}", ReadInteger);
        Console.WriteLine("Double: {0}", ReadDouble);
        Console.WriteLine("String: {0}", ReadString);
    }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» Binary Read Write