How to read a binary file from the middle of the file

C

chinthamani

Hai,
I want to read from a particular point of the file not from the
beginning of the file. It may be from the second line or the third or from
any position, so how is it possible for me to reach the particular
position. Without starting from the file start position.

Regards
S.Vinodh Noel
Software Engineer
Bells Softech Ltd.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

If this is a binary file you do not have a concept of "line" just a raw
array of bytes.
Use FileStream to read the file and use FileStream.Seek to positionate the
punter where you want.
 
J

Jon Skeet [C# MVP]

chinthamani said:
I want to read from a particular point of the file not from the
beginning of the file. It may be from the second line or the third or from
any position, so how is it possible for me to reach the particular
position. Without starting from the file start position.

Others have pointed out the Seek() method. Personally, I always find
that using the Position property is clearer. You only need to specify
one value, for a start - no need to say "from the start" (which is
*almost* always the type of seeking required, IME). The Position
property tends to be overlooked for some reason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top