Scenes
File and FileStream a difference
For example:
Compared to read the file from A to B tub tub water transport.
Use File is the whole buckets poured in, use FileStream is to use the water to slowly transport.
The difference between the FileStream and StreamReader
FileStream operating bytes, i.e., may operate any type of file.
StreamReader is the character of the operation, which can only manipulate text files.
Public concern number
overbearing program ape
acquisition-related programming e-books, tutorials and push for free download.
achieve
First create a new txt file.
Then write a console program
// FileMode.OpenOrCreate: Open file is created there is no open // FileAccess.Read: read-only access to the data of the FileStream fsReader = new new the FileStream ( @ " C: \ the Users \ Administrator \ Desktop \ badao.txt " , FileMode.OpenOrCreate, FileAccess.Read); // declare 5 megabytes of byte array byte [] Buffer = new new byte [ 1024 * 1024 * 5 ]; // return a maximum of 5 megabytes reading r: representative of the actual reading this to the number of valid bytes int R & lt fsReader.Read = (Buffer, 0 , buffer.Length); // byte array each element in accordance with the specified string is decoded into an encoding format stringEncoding.Default.GetString = S (Buffer, 0 , R & lt); // Close stream fsReader.Close (); // release resources occupied fsReader.Dispose (); Console.WriteLine (S); the Console.ReadKey () ;
running result