MemoryStream.WriteTo(FileStream) Question

junfanbl

Member
Joined
Feb 18, 2016
Messages
18
Programming Experience
1-3
I am currently trying to write a memory stream to a file by using the following method: MemoryStream.WriteTo(FileStream). At least this is what I found online. However I don't know how to initialize FileStream or use it properly. To be quite honest, I'm not sure exactly what MemoryStream does, besides move data. I have seen words like "buffer" used to relate to the method but I don't know what that entails. Any information or explanation you guys can provide would be very helpful. Thank you.
 
Here's a list of contructors for FileStream: FileStream Class (System.IO)
You can also use File.Create or File.OpenWrite to get a FileStream: FileStream Class (System.IO)
With FileStream you must at least provide a path and mode, with File method you can get away with only path if you don't want to set other options.
Most help topics also have code examples if you need them.

Streams are used a lot in different contexts to move byte data around, for example files and networking. MemoryStream keeps the data in memory, much like a dynamic array. Streams are often convenient to write or read smaller chunks of data to or from, to minimize memory resources or because transport takes time.
 
Back
Top