I am exporting binary data to
file using BinaryWriter and I'm just outputting the exact same data I
have previously read in using BinaryReader. Stepping through the program,
everything appears to be in order but when I check the binary file,
extra zeros are appearing at seemingly random places.
Has anyone seen this sort of thing with BinaryWriter before?
Loading
AlanPosted Feb 3, 2008, 5:46 AM
It depends on the range of byte values that you are writing to the file.
If the range is just 0 - 127 you can use the ASCIIEncoding which corresponds to code page 20127.
If you're using the full range of 0 - 255, I'd be inclined to use Latin I which is code page 1252. There's a list of Windows code pages here:
http://www.microsoft.com/globaldev/reference/WinCP.mspx
However, as it's binary data, it shouldn't really matter which characters the byte values represent, as long as it's a single byte character set and the other application is reading the file using that assumption.
I suspect the problem at the moment is that the UTF-8 encoding is being used (which I think is the default) and this uses a 2 byte representation for values in the range 128-255.
StevePosted Feb 3, 2008, 12:20 AM
StevePosted Feb 1, 2008, 1:27 PM
AlanPosted Feb 1, 2008, 5:33 AM
This could be due to the encoding being used by the BinaryWriter which is causing some of the data to be filled out with extra zeros.
As long as the data is read back using the same encoding, it shouldn't be a problem as the extra zeros will be stripped back out again.