关山明月

导航

<转>超级简单:将String转化成Stream,将Stream转换成String

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

转自:http://www.cnblogs.com/zhuqil/archive/2010/02/03/Convert-String-to-Stream-and-Stream-to-String.html

posted on 2011-10-31 20:09  关山明月  阅读(392)  评论(0编辑  收藏  举报