File 静态类 ReadAllBytes 和 WriteAllBytes ,用于一次性全部读取和写入小文件的字节码,
                  ReadLine  ReadkAll  用于一次性全部读取字符(字符串)
FileStream 采用流的方式,适用于读取任意大小的文件的字节码,

static void CopyAvi(string source, string target)
{
using (FileStream fsReader = new FileStream(source, FileMode.OpenOrCreate, FileAccess.Read))
{
using (FileStream fsWriter = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
{
byte[] buffer = new byte[ * * ];
while (true)
{
int length= fsReader.Read(buffer, , buffer.Length);
if (length <= )
{
break;
}
fsWriter.Write(buffer, , length);
}
}
}
}

StreamReader和StreamWriter 采用流的方式,用于任意大小文件的字符操作

    static void StreamReaderMethod(string path)
{
using (StreamReader sr = new StreamReader(path, Encoding.UTF8)) {
while (!sr.EndOfStream) {
Console.WriteLine( sr.ReadLine());
}
}
} static void StreamWriterMethod(string path) {
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine("看看有没有覆盖");
}
}

File FileStream StreamReader和StreamWriter的更多相关文章

  1. File FileStream StreamReader StreamWriter C#

    存在各种各样的IO设备,比如说文件File类(字符串文件和二进制文件),可以直接使用File类对文件进行读写操作. 这些各种IO的读取和写入是通过流的形式实现的,基类为Stream,针对各种不同的IO ...

  2. 20151024_003_C#基础知识(File / FileStream / StreamReader/StreamWriter)

    1:绝对路径和相对路径 绝对路径:通过给定的路径直接能在我的电脑中找到这个文件. 相对路径:文件相对于应用程序的路径. 2:编码格式 乱码:产生乱码的原因,就是你保存这个文件所采用的编码,跟你打开这个 ...

  3. C#对文件/目录的操作:Path、File、Directory、FileStream、StreamReader、StreamWriter等类的浅析

    以下类的命名空间都是:System.I/0; 一.Path:主要对文件路径的操作! 常用方法: String path=@"C:\a\b\c\123.txt"; 1-1.Path. ...

  4. 文件流操作(FileStream,StreamReader,StreamWriter)

    大文件拷贝: /// <summary> /// 大文件拷贝 /// </summary> /// <param name="sSource"> ...

  5. 使用StreamReader与StreamWriter进行文本文件读写

    namespace filetest { class FileUtil { public static void WriteFile(string file) { using (FileStream ...

  6. C#基础学习之StreamReader和StreamWriter

    StreamReader和StreamWriter操作字符的 FileStream操作字节的 //使用StreamReader读取文件 using (StreamReader sr=new Strea ...

  7. StreamReader 和 StreamWriter 简单调用

    /* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ####### ...

  8. StreamReader和StreamWriter中文乱码问题

    StreamReader和StreamWriter中文乱码问题 1.写入: string  FilePath = @"E:\Measure.csv"; StreamWriter w ...

  9. File FileStream StreamWriter StreamReader文件读写操作方法

    string path = "D:\\AccountChecking\\Test.txt"; string content = "abcdefg\r\nhigklmn\r ...

随机推荐

  1. jsessionid與cookie關係的理解

    本地測試地址為http://localhost/TEST/login.jsf 當瀏覽器打開cookie時,瀏覽器第一次與服務器建立連接,會創建一個session,並生成一個id即jsessionid, ...

  2. 珠峰-vue

  3. 解决掉你心中 js function与Function的关系的疑问

    前言 在网上有很多关于js function 与 Function直接关系的文章. 但是我感觉过于抽象化了,那么如何是具体化的解释? 正文部分为个人理解部分,如有不对望指出. 正文 <scrip ...

  4. git系列之---工作中项目的常用git操作

    0.本地git的安装 官网下载 1.git 配置 git config user.name  查看 用户名 git config user.email   查看 邮箱 git config --glo ...

  5. JS中new的实现原理及重写

    提到new,肯定会和类和实例联系起来,如: function Func() { let x = 100; this.num = x + } let f = new Func(); 上面的代码,我们首先 ...

  6. JN_0019:CMD命令窗口常用操作

    1,回到根目录下 cd\ 2,

  7. java面对对象入门(4)-程序块初始化

    Java实例初始化程序是在执行构造函数代码之前执行的代码块.每当我们创建一个新对象时,这些初始化程序就会运行. 1.实例初始化语法 用花括号创建实例初始化程序块.对象初始化语句写在括号内. publi ...

  8. css的三种导入方式

    内联样式表 <p style="font-size:50px; color:blue">css内联样式表</p> 内部样式表 <style type= ...

  9. oracle中sql语句的to_date语法

    完整日期:TO_DATE('2009-4-28 00:00:00', 'yyyy-mm-dd hh24:mi:ss'); to_date('2008/09/20','yyyy/mm/dd') 创建视图 ...

  10. 【redis】基于redis实现分布式并发锁

    基于redis实现分布式并发锁(注解实现) 说明 前提, 应用服务是分布式或多服务, 而这些"多"有共同的"redis"; (2017-12-04) 笑哭, 写 ...