Skip to content

Problem in Reading Binary File

Sameer

Asked Feb 12, 2009, 2:13 AM EST1 answer
Share
LinkedInX

Hello all,

I'm trying to read Binary file that contains English as well as some Japanese string like (D001-English &  ????- Japanese).

I'm using following code to do this:

"symbolName = Encoding.Unicode.GetString(binaryReader.ReadBytes(stringLength));"

I can successfully read Japanese string but for English strings, same code gives some garbage value.

If I used

"SymbolName = new string(binaryReader.ReadChars(stringLength));"

it will give me English string correctly, but not Japanese strings.

So, how to read this type of binary file?

Thanks.

Sam

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    Try using UTF8:

    symbolName = Encoding.UTF8.GetString(binaryReader.ReadBytes(stringLength));

    It should correctly decode both the Japanese and English characters.

    Hope that helps!

    Jeff

    0