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

后端 未结 9 1752
别跟我提以往
别跟我提以往 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 10:51

    You can save it as a UTF8 encoded byte array like this:

    ...
    
    BinaryWriter w = new BinaryWriter(fs);
    
    w.Write(UTF8Encoding.Default.GetBytes("test"));
    
    ...
    

提交回复
热议问题