码迷,mamicode.com
首页 > 其他好文 > 详细

Byte|Stream|String测试操作

时间:2015-08-14 15:40:06      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:

static void ByteTest()
{
byte[] namebytearray = System.Text.Encoding.UTF8.GetBytes("zzy");
string readstr = string.Empty;
Stream mstream = new MemoryStream(namebytearray);//字节数组转换成内存流
long length = mstream.Length;
byte[] bufferbyte = new byte[length];
mstream.Read(bufferbyte, 0, int.Parse(length.ToString()));//流读取到字节数组
string resultstr = Encoding.UTF8.GetString(bufferbyte);//字节数组转换成字符串
Console.WriteLine("流转换成字符串:" + resultstr);
using (StreamReader streamReader = new StreamReader(Environment.CurrentDirectory + "/test.txt"))
{
while (!streamReader.EndOfStream)
{
readstr += streamReader.ReadLine() + "\r\n";
}
}

Console.WriteLine("从文件读出来的字符串:\r\n" + readstr);
Console.ReadKey();
}

Byte|Stream|String测试操作

标签:

原文地址:http://www.cnblogs.com/chinaboyzzy/p/4729893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!