/// <summary>
        /// 将流转换成字符串 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="encode">编码方式</param>
        /// <returns></returns>
        public string GetStringByStream(Stream stream, Encoding encod)
        {
            stream.Position = 0;//设置流的起点
            StreamReader read = new StreamReader(stream, encod);
            string content= read.ReadToEnd();
            stream.Flush();
            stream.Close();
            read.Close();
            return content;
        }
        /// <summary>
        /// 字符串转换成流 
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public Stream GetStreamByString(string str, Encoding encod)
        {
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream, encod);
            writer.Write(str);
            writer.Flush();
            stream.Position = 0;
            //writer.Close();
            return stream;
        }

 

posted on 2013-02-19 10:00  路ぺ漫漫  阅读(186)  评论(0编辑  收藏  举报