Question Read text file (encoded)

nkotbox

Active member
Joined
May 28, 2011
Messages
31
Programming Experience
Beginner
I have a text file I am trying to open and I do not know how it is encoded. I am not sure if this is called a binary file or just an encoded file... When I open with notepad I get what is shown below. (this is just a sample of the file, not the complete thing, but this is the first 3.5 lines) Is there any way to read this file in and get the correct output in english?

[XCODE]
ßßß߀ÉítÌ@ ßßß߀ÉítÌ@ € ßßßß œaîtÌ@ € ßßß߀©'"tÌ@ € ßßß߀²õT"tÌ
ßßß߀>0a'tÌ@ ßßß߀>0a'tÌ@ € ßßßß —´m'tÌ ßßß߀ù=(tÌ@ ßßß߀ù=(tÌ@ €
ßßßß ZR>(tÌ ßßß߀N»ñ(tÌ@ ßßß߀N»ñ(tÌ@ € ßßßß zý(tÌ ßßß߀Ñv)tÌ@
ßßß߀Ñv)tÌ@ € ßßß߀“ù)tÌ
[/XCODE]
 
I very much doubt that it is a text file, otherwise Notepad wouldn't display it's contents as gibberish. The fact that a file has a ".txt" extension does not make it a text file, any more than slapping a label that says "sugar" onto a jar of salt makes it a jar of sugar. i'd say that what you have there is a binary file. That simply means that the file contains bytes that represent data other than text, so the mapping could be absolutely anything. You need to go back to the source of the file and ask them what it represents and how to read it.
 
I should not have said txt file. It is a dat file which I guessed was some type of txt file with encoding. I used binaryreader and what is posted below is a portion of what was returned.

Now when the other company opens the file they get some raw data in text all nicely formatted. Will I be able to decipher this data from the file or no?

[XCODE]
223
223
128
201
3
204
64
0
0
0
223
223
128
201
3
204
64
[/XCODE]
 
The other company must have a tool that reads the file as binary then, rather than as text. Presumably they are saving 32-bit numbers, so each four bytes in the file will respresent a number. If you want to display the data as text then you need to read the binary numbers, either using a BinaryReader or some other way, then convert each number to a String and then do with that as you will. Here's an example that would read such a file and then display the results as numbers in a TextBox with each number on a different line:
Dim numbers As New List(Of Integer)

Using file As New FileStream(filePath, FileMode.Open),
      reader As New BinaryReader(file)
    Dim fileLength = file.Length

    Do Until file.Position = fileLength
        numbers.Add(reader.ReadInt32())
    Loop
End Using

Dim strings = Array.ConvertAll(numbers.ToArray(), Function(n) n.ToString())

TextBox1.Text = String.Join(Environment.NewLine, strings)
 
The most useful way to display this kind of data is in hex. We would probably be able to make more sense of it if you posted it that way to begin with.

VB.NET:
DF DF DF DF    80    05 C9 ED 03    74 CC 01    40 20
DF DF DF DF    80    05 C9 ED 03    74 CC 01    40 20        80 20
DF DF DF DF    20    9C-61 EE 03    74 CC 01    40 01 20     80 20 
DF DF DF DF    80    04 A9 27 22    74 CC 01    40 20        80 20
DF DF DF DF    80    B2 F5 54 22    74 CC 01 
DF DF DF DF    80    3E 30 61 27    74 CC 01    40 20
DF DF DF DF    80    3E 30 61 27    74 CC 01    40 20        80 20
DF DF DF DF    20    97 B4 6D 27    74 CC 01    20 
DF DF DF DF    80    C3 B9 3D 28    74 CC 01    40 20 
DF DF DF DF    80    C3 B9 3D 28    74 CC 01    40 20        80 
DF DF DF DF    20    5A 52 3E 28    74 CC 01    20
DF DF DF DF    80    4E BB F1 28    74 CC 01    40 20
DF DF DF DF    80    4E BB F1 28    74 CC 01    40 20        80 20
DF DF DF DF    20    7A 0E FD 28    74 CC 01    20
DF DF DF DF    80    D1 76    29    74 CC 01    40
DF DF DF DF    80    D1 76    29    74 CC 01    40 20        80 20
DF DF DF DF    80    93 F9 81 29    74 CC 01

There's definitely an order to the madness here but without knowing what the data is or what it should decode into, there is no way to tell. At first glance it looks like packets of some sort, with some command structures. The data part seems to be the bytes in the third column, but there are also inconsistencies. From the length of each "packet" it doesn't seem to be 32-bits aligned, rather byte-aligned.
 
Last edited:
Back
Top