C#转换为字节字符串写入txt文件 [英] c# convert byte to string and write to txt file

查看:97
本文介绍了C#转换为字节字符串写入txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换,例如字节[] B =新的字节[1]; B〔1] = 255 字符串?
我需要一个字符串变量值为255字符串文本=255; 键,然后将其存储在一个文本文件

How can i convert for example byte[] b = new byte[1]; b[1]=255 to string ? I need a string variable with the value "255" string text= "255";and then store it in a text file?

推荐答案

从字节开始:

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



如果你从字符串开头的:

and if you start from string:

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

这篇关于C#转换为字节字符串写入txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆