关于文件读写的一些总结

File:当你读写的文件是小文件,可以考虑File.
     1.读写文件文件。可以使用ReadAllText()  ReadAllLines()
     2.如果读写非文本文件:ReadAllBytes[]

FileStream:读取大文件:           

        usint(FileStream fsRead=new FileStream(@"d:\aa.wmv",FileMode.Open)

   {

            using (FileStream fsWrite = new FileStream(@"d: t.sdfs", FileMode.Create))
                {
                    //内存中创建的
                    byte[] bytes = new byte[1024*1024*10];
                    int count = 0;
                    while (true)
                    {
                        //将数据读取到数组  count就是返回当前读取到的字节数
                        count = fsRead.Read(bytes, 0, bytes.Length);
                        if (count == 0)
                        {
                            break;
                        }
                        //将数组中的数据写入到文件
                        fsWrite.Write(bytes, 0, count);
                    }
                    MessageBox.Show("ok");
                }
            }

StreamWriter/SteamReader:可以进行一行数据的读写,它是专门对文本文件进行操作

原文地址:https://www.cnblogs.com/Zouzhe/p/3828638.html