CSharp examples for File IO:MemoryStream
Create TextWriter via StreamWriter and MemoryStream
using System;//from ww w . j a v a 2 s. c om using System.IO; public class Program { public static void Main(string[] args) { string data = "test/ntest/ntest/n"; // \n equiv to 2 bytes, so 18 bytes. Console.WriteLine("Original data:\n{0}", data); byte[] buffer = new byte[data.Length + 20]; MemoryStream ms = new MemoryStream(buffer); TextWriter writer = new StreamWriter(ms); if (ms.CanWrite) { Console.WriteLine("Can write to stream."); } writer.WriteLine(data); writer.Flush(); } }