Csharp/C#教程:c#将byte转换为string并写入txt文件分享


c#将byte转换为string并写入txt文件

我如何转换例如byte[] b = new byte[1]; b[1]=255 byte[] b = new byte[1]; b[1]=255到字符串? 我需要一个字符串变量,其值为“255” string text= "255"; 然后将其存储在文本文件中?

从字节开始:

  byte[] b = new byte[255]; string s = Encoding.UTF8.GetString(b); File.WriteAllText("myFile.txt", s); 

如果你从字符串开始:

  string x = "255"; byte[] y = Encoding.UTF8.GetBytes(x); File.WriteAllBytes("myFile2.txt", y); 

无需转换为字符串。 你可以使用File.WriteAllBytes

上述就是C#学习教程:c#将byte转换为string并写入txt文件分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 File.WriteAllBytes(@"c:folderfile.txt", byteArray); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1034705.html

(0)
上一篇 2022年1月19日
下一篇 2022年1月19日

精彩推荐