John Smith
John Smith

Reputation: 1005

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?

Upvotes: 0

Views: 55

Answers (1)

Wagner DosAnjos
Wagner DosAnjos

Reputation: 6374

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.

Upvotes: 1

Related Questions