CSharp examples for File IO:MemoryStream
Convert MemoryStream to byte array
using System;//from w w w .j a v a 2 s . c o m 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); Console.WriteLine("Write the bytes actually in the stream:"); foreach (byte b in ms.ToArray()) { Console.Write(b); } } }