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

后端 未结 9 1733
别跟我提以往
别跟我提以往 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:57

    Remember that Java strings are internally encoded in UTF-16.

    So, "test" is actually made of the bytes 0xff, 0xfe (together the byte order mark), 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00.

    You probably want to work with bytes instead of streams of characters.

提交回复
热议问题