Sunday, March 20, 2011

difference between streams

What is the difference between all these classes such as StreamReader, BufferedStream, FileStream, MemoryStream?

From stackoverflow
  • StreamReader: reads a Stream FileStream: represents a stream that can be read from a file MemoyStream: a stream that exists in memory ...

    I think it is all in MSDN StreamReader FileStream MemoryStream BufferedStream

    So, you can use a StreamReader to read a FileStream, or a MemoryStream, etc...

  • We can start by lifting out StreamReader: this one is a class that is used for reading from various streams (such as a MemoryStream or FileStream), but it is not a Stream itself.

    The other ones are simply different implementations of the abstract Stream class, representing data streams with different storage mechanisms; MemoryStream represents data held in memory, FileStream represents data held in a file on disk.

    Some Stream implementation are "wrapped" around other streams in order to provide added functionality (such as the GZipStream and BufferedStream).

    For more detailed information about the different streams, check out their MSDN documentation. You can find a list of Stream class implementations in the .NET Framework towards the end of the page of the Stream class documentation.

  • Best idea will be to read msdn documentation.

    StreamReader Class: Implements a TextReader that reads characters from a byte stream in a particular encoding.

    BufferedStream Class: Adds a buffering layer to read and write operations on another stream. This class cannot be inherited.

    FileStream Class: Exposes a Stream around a file, supporting both synchronous and asynchronous read and write operations.

    MemoryStream Class: Creates a stream whose backing store is memory.

0 comments:

Post a Comment