CSharp examples for File IO:MemoryStream
Seek position in MemoryStream
using System;/*w ww . java2 s . c o m*/ using System.IO; using System.Text; 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 stream2 = new MemoryStream(); stream2.Write(buffer, 0, buffer.Length); stream2.Seek(0L, SeekOrigin.Begin); byte[] newBuffer = new byte[stream2.Length]; stream2.Read(newBuffer, 0, (int)stream2.Length); foreach (byte b in newBuffer) { Console.Write(b); } } }