Filestream to Memorystream

  • Thread starter Thread starter paradigmshift
  • Start date Start date
P

paradigmshift

I am looking at how to move data from a file to a memory stream. This
data will be needed many times over and over so i don't want to have
to rely on the system to keep the information cashed for access. Kind
of an easy question for pros but thats why I figured I would ask here.

Thanks,
 
I am looking at how to move data from a file to a memory stream. This
data will be needed many times over and over so i don't want to have
to rely on the system to keep the information cashed for access. Kind
of an easy question for pros but thats why I figured I would ask here.

Thanks,

Just cpy the FileStream to the MemoryStream.
Unfortunately FileStream does not implement a WriteTo a la
MemoryStream , so you need a temp buffer
 
paradigmshift said:
I am looking at how to move data from a file to a memory stream. This
data will be needed many times over and over so i don't want to have
to rely on the system to keep the information cashed for access. Kind
of an easy question for pros but thats why I figured I would ask here.

Create a buffer (byte array) and the memory stream. Repeatedly read
from the file stream into the buffer, and then write the contents (but
only as much as you read) into the memory stream. Keep going until
reading from the file stream yields no data.

See http://pobox.com/~skeet/csharp/readbinary.html for the reading loop
- the writing to the memory stream is the easy bit!
 
Back
Top