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. MySQL数据库的备份、还原、迁移

    一.单库备份与还原 1.远程连接MySQL数据库 D:\mysql-5.7.14-winx64\bin>mysql -h192.168.2.201 -uroot -pcnbi2018 参数说明: ...

  2. thinkPHP中Model的字段映射问题

    在model定义中不要自己定义相应的字段变量,因为一旦定义,之后的赋值会直接赋给自己定义的属性,但实际上model抽象类重写了__set()方法,将未定义的属性存入了$data里面,写入数据库是也会从 ...

  3. 传智播客C++视频学习笔记(5)

    #include <iostream> using namespace std; void swapInt(int& a, int& b) { int temp = a; ...

  4. linux中其他搜索命令(locate/which/whereis/grep)

    目录 locate which whereis grep locate 解释 命令名称:locate 命令所在路径:/usr/bin/locate 执行权限:所有用户 功能描述:在文件资料库中查找文件 ...

  5. Python面试(基础)

    第一部分 必答题 1,简述列举了解的编程语言及语言间的区别? Python 解释型语言,代码简洁,易懂 C语言 编译型语言,底层语言 c++ 编译型语言,在C语言基础上加了面向对象 Java 混合型语 ...

  6. python基础练习,循环、列表、字典、数组

    # encoding: utf-8 ''' @author: mark @file: 20200214.py @time: 2020/2/14 14:21 @software: PyCharm ''' ...

  7. PL/SQL不安装Oracle连接,Oracle instantclient安装

    ================================ ©Copyright 蕃薯耀 2020-01-07 https://www.cnblogs.com/fanshuyao/ 第一步: 下 ...

  8. [Contract] Solidity 判断 mapping 值的存在

    比如 mapping(address => uint) tester,只需要判断 mapping 是否为默认值 0, tester[msg.sender] == 0 "You can ...

  9. spring security之web应用安全

    一.什么是web应用安全,为了安全我们要做哪些事情? 保护web资源不受侵害(资源:用户信息.用户财产.web数据信息等)对访问者的认证.授权,指定的用户才可以访问资源访问者的信息及操作得到保护(xs ...

  10. php请求相关

    参数接收 原生 $_POST 接收application/x-www.form-urlencoded 和multipart/form-data,对body中的数据进行urldecode解码 file_ ...