The difference between FileStream and Binaryreader,binarywriter,streamreader,streamwriter

Source: Internet
Author: User

FileStream is useful for reading and writing files on the file system , FileStream cache inputs and outputs for better performance. The FileStream object represents a stream that points to a file on a disk or network path. This class provides a way to read and write sections in a file, but often uses StreamReader or StreamWriter to perform these functions. This is because the Filesteam class operates on byte and byte arrays, and the Stream class operates on character data. FileStream can only handle raw bytes (raw byte), and the ability to process raw bytes using the FileStream class can be used to process any data file. By reading Byte data, the FileStream object can be used to read graphics and sounds. The price is that the FileStream class cannot read the data directly into the string.

FileStream common properties and methods.

Flush (): Writes data from the current buffer to the file.

StreamReader class

Implements a textreader that reads characters from a byte stream in a specific encoding.

StreamWriter class

Implements a TextWriter that writes characters to a stream in a specific encoding

TextReader class

Represents a reader that can read a series of contiguous characters.

TextWriter class

Represents a writer that can write an ordered series of characters. The class is an abstract class.

BinaryReader class

Reads the primitive data type as a binary value with a specific encoding. You can think of BinaryReader as an extension to StreamReader, which has a richer coding style than StreamReader.

BinaryWriter

Writes a primitive type to a stream in binary form and supports writing a string with a specific encoding. Same as BinaryReader.

The BinaryWriter class and the BinaryReader class are used to read and write data, and it can specify that reads are written as strings.

StreamReader.BaseStream

Returns the underlying stream.

The difference between BinaryReader and FileStream

BinaryReader can specify Encoding, which implements reading strings.

The FileStream is readable and writable, supports asynchronous operations, and encapsulates unmanaged IO handles, supporting only file streams.

BinaryReader is read only, does not support asynchronous operations, but supports any stream that inherits to stream, such as Networkstream,memorystream.

The difference between FileStream and Binaryreader,binarywriter,streamreader,streamwriter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.