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