StreamReader和StreamWriter
FileStream 是操作字节的
StreamReader跟StreamWriter是操作字符串的
操作文件的方法的命名空间都是IO
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace StreamReader跟StreamWriter
{
class Program
{
static void Main(string[] args)
{
//使用StreamReader来读取一个文件
using (StreamReader sr = new StreamReader(@"F:\程序测试文件夹\aoe.txt",Encoding.UTF8))
{
while(!sr.EndOfStream )
{
Console.WriteLine(sr.ReadLine());
}
Console.ReadKey();
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace StreamReader跟StreamWriter
{
class Program
{
static void Main(string[] args)
{
//使用StreamReader来读取一个文件
//using (StreamReader sr = new StreamReader(@"F:\程序测试文件夹\aoe.txt",Encoding.UTF8))
//{
// while(!sr.EndOfStream )
// {
// Console.WriteLine(sr.ReadLine());
// }
// Console.ReadKey();
//} //使用StreamWriter来写入一个文本文件
using (StreamWriter sw = new StreamWriter(@"F:\程序测试文件夹\qwer.txt"))
{
sw.WriteLine("爱丽丝凯迪拉克金克拉撒旦发刻录机啊圣诞快乐就奥克兰就看来简洁大方深刻理解上的法"); }
Console.WriteLine("ok");
Console.ReadKey(); }
}
}
这种写入都是会把之前的覆盖掉的,要想不覆盖,需要在创建StreamWriter对象的时候,重载里面有个bool Append,来确认是否追加,如果是追加那就填个true,不然就默认覆盖

StreamReader和StreamWriter的更多相关文章
- C#对文件/目录的操作:Path、File、Directory、FileStream、StreamReader、StreamWriter等类的浅析
以下类的命名空间都是:System.I/0; 一.Path:主要对文件路径的操作! 常用方法: String path=@"C:\a\b\c\123.txt"; 1-1.Path. ...
- 文件流操作(FileStream,StreamReader,StreamWriter)
大文件拷贝: /// <summary> /// 大文件拷贝 /// </summary> /// <param name="sSource"> ...
- StreamReader 和 StreamWriter 简单调用
/* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ####### ...
- C#基础学习之StreamReader和StreamWriter
StreamReader和StreamWriter操作字符的 FileStream操作字节的 //使用StreamReader读取文件 using (StreamReader sr=new Strea ...
- StreamReader和StreamWriter中文乱码问题
StreamReader和StreamWriter中文乱码问题 1.写入: string FilePath = @"E:\Measure.csv"; StreamWriter w ...
- File FileStream StreamReader和StreamWriter
File 静态类 ReadAllBytes 和 WriteAllBytes ,用于一次性全部读取和写入小文件的字节码, ReadLine ReadkAll 用于一 ...
- C#--几个数据流Stream;StreamReader;StreamWriter;MemoryStream;BufferStream;
命名空间:System.IO; Stream: 各种流的基类,不能时行查找操作,Position属性不能修改.读取时不Position不会自动移动, HttpWebRequest webreq = ( ...
- 文件流StreamReader和StreamWriter的使用
using (StreamReader sr = new StreamReader(@"C:\Users\shuai\Desktop\文件流读取.txt", Encoding.De ...
- 使用StreamReader与StreamWriter进行文本文件读写
namespace filetest { class FileUtil { public static void WriteFile(string file) { using (FileStream ...
- StreamReader与StreamWriter
StreamReader实现了抽象基类TextReader类,而StreamWriter实现了抽象基类TextWriter.分别用于对流的读取与写入. 先从StreamReader说起 一.构造方法 ...
随机推荐
- .Net 7 的AOT的程序比托管代码更容易破解?
楔子 .Net 7的一个重要功能是把托管的源码编译成Native Code,也就是二进制文件.此举看似增加了程序反编译难度,实际上是减少了程序的破解难度.本篇在不触及整个程序架构的前提下,以简单的例子 ...
- Java的深拷贝和浅拷贝的区别
一.拷贝的引入 (1).引用拷贝 创建一个指向对象的引用变量的拷贝. Teacher teacher = new Teacher("Taylor",26); Teacher oth ...
- Ubuntu snap 下载慢
解决方法 sudo apt-get install snapd sudo snap install snap-store sudo snap install snap-store-proxy sudo ...
- 移动端安卓开发学习记录--Android Studio使用adb链接夜神模拟器常用指令
1.下载安装模拟器,打开模拟器,本步骤不再赘述 2.打开模拟机器安装路径,在地址栏输入cmd,回车,就会打开命令行窗口 3.输入 nox_adb.exe connect 127.0.0.1:62001 ...
- 解决安装node-sass报错的方法
1.下载源码放到本地搞~~ 适合内网开发的苦孩子们~~~ 先进入https://github.com/sass/node-sass/releases下载自己需要的包 可以点击tags然后找到自己需要的 ...
- BUG日记--——Linux安装Docker
1.yum makecache fast不适合Centos8 2.解决办法 3.doucke的使用 1.关闭防火墙 # 关闭 systemctl stop firewalld # 禁止开机启动防火墙 ...
- mov eax,dword ptr[0x00aff834] 和 lea eax,[0x00aff834]区别
mov eax,dword ptr[0x00aff834] 和 lea eax,[0x00aff834]区别 mov eax,[内存]是将内存的值赋值给eax,而lea是直接将地址值赋值给eax 因此 ...
- SpringBoot学习笔记 - 构建、简化原理、快速启动、配置文件与多环境配置、技术整合案例
[前置内容]Spring 学习笔记全系列传送门: Spring学习笔记 - 第一章 - IoC(控制反转).IoC容器.Bean的实例化与生命周期.DI(依赖注入) Spring学习笔记 - 第二章 ...
- 浅谈Python中的with,可能有你不知道的
Python中的with,没那么简单,虽然也不难 https://docs.python.org/zh-cn/3.9/reference/compound_stmts.html#the-with-st ...
- Swagger2多包扫描
package com.xf.config; import org.springframework.context.annotation.Bean; import org.springframewor ...