using System; using System.IO; using System.Text; namespace CSharpConvertString2Stream { class Program { static void Main( string[] args ) { string str = "This is the test string."; //convert string to stream byte[] array = Encoding.ASCII.GetBytes(str); MemoryStream stream = new MemoryStream(array); //convert stream to string StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); Console.WriteLine(text); Console.ReadLine(); } } }
时间: 2024-11-05 04:31:43