FileStream StreamWriter StreamReader BinaryReader
FileStream vs/differences StreamWriter?
http://stackoverflow.com/questions/4963667/filestream-vs-differences-streamwriter
What is different between FileStream and StreamWriter in dotnet?
A FileStream
is a Stream
. Like all Streams it only deals with byte[]
data.
A StreamWriter
is a TextWriter
, a Stream-decorator. A TextWriter converts or encodes Text data like string or char to byte[]
and then writes it to the linked Stream
.
What context are you supposed to use it? What is their advantage and disadvantage?
You use a bare FileStream when you have byte[]
data. You add a StreamWriter
when you want to write text.
Is it possible to combine these two into one?
Yes. You always need a Stream to create a StreamWriter. System.IO.File.CreateText("path")
will create them in combination and then you only have to Dispose() the outer writer.
StreamReader vs BinaryReader?
http://stackoverflow.com/questions/10353913/streamreader-vs-binaryreader
Both StreamReader and BinaryReader can be used to get data from binary file
Well, StreamReader
can be used to get text data from a binary representation of text.
BinaryReader
can be used to get arbitrary binary data. If some of that binary data happens to be a representation of text, that's fine - but it doesn't have to be.
Bottom line:
- If the entirety of your data is a straightforward binary encoding of text data, use
StreamReader
. - If you've fundamentally got binary data which may happen to have some portions in text, use
BinaryReader
So for example, you wouldn't try to read a JPEG file with StreamReader
.
FileStream StreamWriter StreamReader BinaryReader的更多相关文章
- File FileStream StreamWriter StreamReader文件读写操作方法
string path = "D:\\AccountChecking\\Test.txt"; string content = "abcdefg\r\nhigklmn\r ...
- 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"> ...
- C#中FileStream和StreamWriter/StreamReader的区别
首先致谢!转自:http://blog.sina.com.cn/s/blog_67299aec0100snk4.html 本篇可能不是非常深入,但是胜在清晰明了 FileStream对象表示在 ...
- c#StreamWriter,StreamReader类(主要用于文本文件访问)
1.为什么要使用StreamReader或者StreamWriter 如果对文本文件需要读取一部分显示一部分则使用FileStream会有问题,因为可能FileStream会在读取的时候把一个汉字的字 ...
- 【基础巩固】文件流读写、大文件移动 FileStream StreamWriter File Path Directory/ ,m资料管理器(递归)
C#获取文件名 扩展名 string fullPath = @"d:\test\default.avi"; string filename = Path.GetFileName(f ...
- StreamWriter StreamReader
private void WriteLoginJsonData(object jsonData) { using (FileStream writerFileStream = new FileStre ...
- 利用FileStream实现多媒体文件复制
利用FileStream实现多媒体文件复制的主要思路在于利用两个FileStream对象,一个读取字节,另一个对象写入字节既可. 涉及知识点: 1.通常我们操作的File类,FileS ...
- FileStream和BinaryReader,BinaryWriter,StreamReader,StreamWriter的区别
FileStream对于在文件系统上读取和写入文件非常有用,FileStream缓存输入和输出,以获得更好的性能.FileStream对象表示在磁盘或网络路径上指向文件的流.这个类提供了在文件中读写字 ...
随机推荐
- python字符串,常用编码
Python的字符串和编码 1.常用编码 与python有关的编码主要有:ASCII.Unicode.UTF-8 其中ASCII如今可以视作UTF-8的子集 内存中统一使用Unicode编码(如记事本 ...
- buf.indexOf()
buf.indexOf(value[, byteOffset][, encoding]) value {String} | {Buffer} | {Number} byteOffset {Number ...
- Cropping multiple images the same way
The tools we’ll be using are =GIMP= and =mogrify= (from the ImageMagick suite), so make sure that yo ...
- 杭电1722 Cake (分蛋糕)
#include<cstdio> int f(int m,int n) { ) return n; else return f(n,m%n); } int main() { int m,n ...
- Java中static、final、static final的区别
final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final修饰的属性跟具体对象有关,在运行期 ...
- [luoguP2401] 不等数列
传送门 f[i][j]表示前i个数有j个<的方案数 #include <cstdio> #define N 1001 #define p 2015 int n, k; int f[N ...
- HDU 3602 2012【01 背包变形】
题意: 有 n 个团队和 m 艘船,每艘船的载客量为 k,每个团队的人数为ai+1 ,转载该团队可获利润 bi,要求每个团队的所有人必须在同一艘船上, 且团队优先级高的团队所在船编号不能大于优先级低的 ...
- es6常用语法和特性
简介 首先,在学习之前推荐使用在线转码器 Traceur 来测试 Demo,避免 babel 下的繁琐配置,从而产生畏难情绪. let 命令 在 ES6 之前,JS 只能使用 var 声明变量,或者省 ...
- LOJ#541. 「LibreOJ NOIP Round #1」七曜圣贤
有一辆车一开始装了编号0-a的奶茶,现有m次操作,每次操作Pi在[-1,b),若Pi为一个未出现过编号的奶茶,就把他买了并装上车:若Pi为一个在车上的奶茶,则把他丢下车:否则,此次操作为捡起最早丢下去 ...
- 1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组
1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组 #include <iostream> #include <string> #include & ...