Search or Read thru a text binary file (.dat)

cubangt 1 Reputation point
2021-07-16T03:43:40.407+00:00

Im trying to learn how to work with binary text files, at work we have some .dat files and the other team said that its a text binary format. They are large in file size, some as large as 200mb.
I found a few examples on reading the files into a byte array, but so far all the examples seems to be small 1 or 2 lines of strings that they convert to and convert back.

I started with this:

byte[] bHex = File.ReadAllBytes(fileName);

        //////Reverse the HEX array for readability  
        foreach (byte[] c in bHex.Reverse())  
        {  
            i++;  
            // 12 to 21 byte in the reverse order for interseted value in ticks"  

            if (i > 12 && i < 21)  
                st.Append(BitConverter.ToString(c));  
        }  

For starters i just want to be able to read thru the file, or i guess output each line/row in the file in a readable format(string)

From the looks of what i can see in the hex editor, its lines of 8 individual 16-bit values in hexadecimal, but considering this is my first or second time working with hex files, not 100% sure.

115206-hex.png

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.