string与stream的相互转换
1 string test = “This is string″; 2 3 // convert string to stream 4 MemoryStream stream = new MemoryStream(); 5 StreamWriter writer = new StreamWriter( stream ); 6 writer.Write( test ); 7 writer.Flush(); 8 9 // convert stream to string 10 stream.Position = 0; 11 StreamReader reader = new StreamReader( stream ); 12 string text = reader.ReadToEnd();