Results 1 to 2 of 2

Thread: MemoryStream.WriteTo(FileStream) Question

  1. #1
    junfanbl is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Feb 2016

    MemoryStream.WriteTo(FileStream) Question

    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.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    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.
    How to format posts with code blocks etc - present the problem/post properly

    Visual Studio Community 2017


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts