file,memory,stream,write,read

rou97 7/29/2016 0

this codes will let you write a file to memory stream or read a file from memory stream

C#
//This code writes down MemoryStream to a file:
FileStream file = new FileStream("file.bin", FileMode.Create, System.IO.FileAccess.Write);byte[] bytes = new byte[ms.Length];
ms.Read(bytes, 0, (int)ms.Length);
file.Write(bytes, 0, bytes.Length);
file.Close();
ms.Close();
//and this reads a file to a MemoryStream :

MemoryStream ms = new MemoryStream();FileStream file = new FileStream("file.bin", FileMode.Create, FileAccess.Read);
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
file.Close();
ms.Close();
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments