string与stream的相互转换(C#)

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();  

 

string与stream的相互转换(C#)

上一篇:C#中ToString()格式详解


下一篇:WindowServer2003中IIS6.0允许运行32位程序