John Smith John Smith - 23 days ago 6
Vb.net Question

Wrong byte is written to file

I am writing a few bytes to a newly created file in Visual Basic.
The following code is executed:

compressedFileStream.WriteByte(&H00)
compressedFileStream.WriteByte(&H00)
compressedFileStream.WriteByte(&H00)
compressedFileStream.WriteByte(&H00)
compressedFileStream.WriteByte(&H00)
compressedFileStream.WriteByte(&HD5)
compressedFileStream.WriteByte(&H55)
compressedFileStream.WriteByte(&H6E)
compressedFileStream.WriteByte(&H49)


Unfortunately the output is not what I wrote. Using Notepad++ I see this result:

Actual Result

Creation of compressedFileStream:

Using compressedFileStream As FileStream = File.Create(ArchivePath & ".zip")


The D0 and B5 are wrong. After those two bytes that magically appeared it will continue with the correct bytes (55, 6E and 49). Did anyone actually experience this or does anyone know what can cause this?

Answer

I tried your code and it works as expected. Is there any other process that takes place after the WriteByte statements are executed?

Or, perhaps Notepad++ is playing tricks on you.