/// <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; }