文本读写
来源:互联网 发布:海诺网络 编辑:程序博客网 时间:2024/06/05 08:56
使用FileStream读取
using(FileStream fs = File.OpenRead(@"/Users/wxl/Workplace/test.txt")){ byte[] arr = new byte[100]; UTF8Encoding encoding = new UTF8Encoding(true); while(fs.Read(arr, 0, arr.Length) > 0) { Console.WriteLine(encoding.GetString(arr)); }}
使用FileStream写入
using(StreamWriter ws = new StreamWriter(@"/Users/wxl/Workplace/test.txt")){ string[] arr = new string[]{"hello\n","汪晓龙"}; foreach(var str in arr) { ws.WriteLine(str); }}
使用StreamReader读取
using(StreamReader sr = new StreamReader(@"/Users/wxl/Workplace/test.txt")){ string line; while((line = sr.ReadLine()) != null) { Console.WriteLine(line); }}
使用StreamWriter写入
using(StreamWriter ws = new StreamWriter(@"/Users/wxl/Workplace/test.txt")){ string[] arr = new string[]{"hello","world"}; foreach(var str in arr) { ws.WriteLine(str); }}
阅读全文
0 0
- 读写文本
- 读写文本
- 文本读写
- 读写文本的类
- C#读写文本
- evc 读写文本问题
- C++ 文本读写
- vb.net读写文本
- 文本的读写java
- C++读写文本
- c#文本读写
- C++读写unicode文本
- python 文本读写操作
- android 读写文本
- 文本的读写
- 文本的读写
- RandomAccessFile 文本随机读写
- java简单读写文本
- hdu 6143 Killer Names(组合计数)(DP)
- MyBatis:系列讲解
- 22、数据压缩-霍夫曼编码
- SpringMVC的在线人数统计监听器
- vuejs之路之--事件绑定
- 文本读写
- init
- JavaWeb学习之请求转发和重定向
- POJ题目分类
- js 笔记
- 剑指offer面试题[6]-重建二叉树
- pthread_cond_timewait
- 平安科技面试总结
- Java:使用Iterator迭代器遍历集合数据