Binary Writer Reader
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");
BinaryWriter bw = new BinaryWriter(f.OpenWrite());
Console.WriteLine("Base stream is: {0}", bw.BaseStream);
double aDouble = 1234.67;
int anInt = 34567;
char[] aCharArray = { 'A', 'B', 'C' };
bw.Write(aDouble);
bw.Write(anInt);
bw.Write(aCharArray);
bw.Close();
BinaryReader br = new BinaryReader(f.OpenRead());
int temp = 0;
while (br.PeekChar() != -1) {
Console.Write("{0,7:x} ", br.ReadByte());
if (++temp == 4) {
Console.WriteLine();
temp = 0;
}
}
}
}
Related examples in the same category