BinaryReader.PeekChar() : BinaryReader « System.IO « C# / C Sharp by API






BinaryReader.PeekChar()

 



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

1.new BinaryReader(FileStream fs)
2.BinaryReader.BaseStream
3.BinaryReader.ReadByte()
4.BinaryReader.ReadChar()
5.BinaryReader.ReadDecimal()
6.BinaryReader.ReadDouble()
7.BinaryReader.ReadInt32()
8.BinaryReader.ReadString()