Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,897 answers

573 users

How to read int values from binary file with BinaryReader in C#

Learn & Practice SQL


279 views
asked Mar 12, 2015 by avibootz
edited May 7, 2015 by avibootz

1 Answer

0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (BinaryReader br = new BinaryReader(File.Open("d:\\data.bin", FileMode.Open)))
            {
                int pos = 0;
                int length = (int)br.BaseStream.Length;

                while (pos < length)
                {
                    int i = br.ReadInt32();

                    Console.WriteLine(i);

                    pos += sizeof(Int32);
                }
            }
        }
    }
}

/*
run:
   
24
45
94
41
70
73
26
60
36
58

*/




answered Mar 12, 2015 by avibootz

Related questions

1 answer 2,581 views
1 answer 96 views
1 answer 89 views
2 answers 137 views
2 answers 149 views
...