Why does BinaryWriter prepend gibberish to the start of a stream? How do you avoid it?

后端 未结 9 1754
别跟我提以往
别跟我提以往 2020-11-30 10:11

I\'m debugging some issues with writing pieces of an object to a file and I\'ve gotten down to the base case of just opening the file and writing \"TEST\" in it. I\'m doing

9条回答
  •  情书的邮戳
    2020-11-30 10:39

    As Henk pointed out in this answer, this is the length of the string (as a 32-bit int).

    If you don't want this, you can either write "TEST" manually by writing the ASCII characters for each letter as bytes, or you could use:

    System.Text.Encoding.UTF8.GetBytes("TEST")
    

    And write the resulting array (which will NOT contain a length int)

提交回复
热议问题