using System;
using System.IO;
using System.Text;
namespace CSharpConvertString2Stream
{
class Program
{
static void Main( string[] args )
{
string str = "Testing 1-2-3"; //convert string 2 stream
byte[] array = Encoding.ASCII.GetBytes(str);
MemoryStream stream = new MemoryStream(array); //convert stream 2 string
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();
Console.WriteLine(text);
Console.ReadLine();
}
}
}
另:
String转换为byte数组用
byte[] arr = System.Text.Encoding.Default.GetBytes("abcde")
byte数组转换为String用:
string str = System.Text.Encoding.Default.GetString(arr);