The specific usage is not to repeat.
Record the difference in usage
StreamReader:
New FileStream (@ "D:\Readme.txt", FileMode.Open); New StreamReader (FS);
Streamwrite:
New FileStream (@ "D:\a.txt", filemode.createnew); New StreamWriter (Fs,encoding.utf8);
Filesteam:
FileStream fs1=New Filesteam (path,filemode.open,fileaccess.read); Fs.read (...) FileStream FS2=new Filesteam (path,filemode.open,fileaccess.write); Fs.write (...)
FileStream and Streamxxxx have read, write methods but where are their differences?
- The biggest difference is that Streamreader/streamwriter is manipulating character data (char), and FileStream is manipulating byte data (byte), The default encoding for the FileStream and Streamxxxx classes is UTF8, and a Chinese character is 2 characters, so the Streamxxxx class is often used for opening and saving text, while FileStream is used for data transfer.
- FileStream is not able to specify the encoding (because it sees only the binary form of the file, of course it does not matter coding), so if there is Chinese text, the need to transcode.
- FileStream is a lower-level class that can simply read a file to a buffer, while the Streamxxxx class encapsulates some advanced methods, such as ReadLine () (read by row)
- FileStream can specify FileMode, FileAccess, FileShare, fileoptions and other file access control permissions, share permissions, etc., greatly expanded the flexibility of file reading and writing, And Filestreamfilestream also provides the Beginread/beginwrite (asynchronous read-write) operation method
The difference between StreamReader and Streamwrite and FileStream