Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read binary file in C# from specific position

Tags:

c#

binary-data

Is it possible to read a large binary file from a particular position?

I don't want to read the file from the beginning because I can calculate the start position and the length of the stream I need.

like image 685
Skuami Avatar asked Jul 13 '11 06:07

Skuami


People also ask

How do I read a binary file in C?

Use the fread Function to Read Binary File in C FILE* streams are retrieved by the fopen function, which takes the file path as the string constant and the mode to open them. The mode of the file specifies whether to open a file for reading, writing or appending.

Can binary files be read?

Binary files are not human readable and require a special program or hardware processor that knows how to read the data inside the file. Only then can the instructions encoded in the binary content be understood and properly processed.

How do you read and write binary file and text file explain with C program?

Read, write and seek operations can be performed on binary files with the help of fread(), fwrite() and fseek() functions, respectively. After reading or writing a structure, the file pointer is moved to the next structure. The fseek() function can move the pointer to the position as requested.

What is a binary file in C?

Binary fileIt contains 1's and 0's, which are easily understood by computers. The error in a binary file corrupts the file and is not easy to detect. In binary file, the integer value 1245 will occupy 2 bytes in memory and in file. A binary file always needs a matching software to read or write it.


1 Answers

        using (FileStream sr = File.OpenRead("someFile.dat"))
        {
            sr.Seek(100, SeekOrigin.Begin);
            int read = sr.ReadByte();
            //...
        }
like image 88
Petar Ivanov Avatar answered Sep 19 '22 12:09

Petar Ivanov