zoukankan      html  css  js  c++  java
  • 关于文件读写的一些总结

    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:可以进行一行数据的读写,它是专门对文本文件进行操作

  • 相关阅读:
    HTML 5 全局属性
    微软build 2015
    写个程序登陆58同城
    工厂方法
    简单工厂
    System.Data.SQLite兼容32位和64位问题
    利用Socket实现的两个程序的通信
    最近的工作总结
    Canvas路径、描边、填充
    HTML5阴影与渐变
  • 原文地址:https://www.cnblogs.com/Zouzhe/p/3828638.html
Copyright © 2011-2022 走看看