There are many useful libraries in. NET to read and write files on your hard disk. Commonly used are:
File:1. When to use: when the read and write pieces are small size, and can be read and write operations at the same time to use
2. Different ways to read and write file types are not the same.
ReadAllBytes () Writeallbyte (): can read and write any type of file (FileStream is encapsulated)
ReadAllLines () ReadAllText ():(inside package is Streamwriter,streamreader), can only read and write text type file
FileStream:
1. When reading and writing large files, it can customize the size of the read-write array
2. A flow can only do one thing: if you need to read and write then you need to create two streams
3. READ: Reading data to an array write is to write the data of the array back to the file (type conversion)
Use the FileStream class to read and write a movie example code:
1 //Read2 using(FileStream fsread =NewFileStream (@"F:\, Ms. Cang. avi", FileMode.Open))3 {4 using(FileStream fswrite =NewFileStream (@"d:\ learning. avi", FileMode.Create))5 {6 //the length of the custom array7 byte[] bytes =New byte[1024x768];8 //A loop is required when the end of the file is not read9 while(Fsread.position <fsread.length)Ten { One //when read, the Position property automatically changes, remembering where it is currently read, in bytes A //count can get the number of bytes currently read to - intCount = Fsread.read (Bytes,0, Bytes. Length); - if(Count = =0) the { - Break; - } - //Write +Fswrite.write (Bytes,0, count);//just write the number of bytes read to it. - } + } AMessageBox.Show ("OK"); at}
Streamreader/streamwrite:
1. Read and write only to text files
2. It can read and write by line