Warm tip: This article is reproduced from serverfault.com, please click

Problem in write ascii string builder to a file

发布于 2020-12-01 11:52:13

I try to write a string include some character to a file like that:

StringBuilder sb= new StringBuilder();
sb.Append("3S@Þ>‡g3¶UH3úUH3?UH3UH3âUH3ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿUH3ÇUH3ÿÿÿÿUH3EêL3");
File.WriteAllText(outputFilename, sb.ToString());

but in the end, I have a file include this:

3S@Þ>‡g3¶UH3úUH3?UH3UH3âU

I just know my file must be like that:

enter image description here

How can I write this string to a file .bin?

Questioner
ehsanHB
Viewed
0
3,888 2020-12-01 20:39:38

Thanks to @Jeroen Mostert.

I use File.WriteAllBytes(new byte[] { 0x33, 0x53, 0x40, 0xde, ...}) and work correctly.