FileStream vs/differences StreamWriter?

http://stackoverflow.com/questions/4963667/filestream-vs-differences-streamwriter

What is different between FileStream and StreamWriter in dotnet?

FileStream is a Stream. Like all Streams it only deals with byte[] data.

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的更多相关文章

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

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

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

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

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

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

  4. C#中FileStream和StreamWriter/StreamReader的区别

    首先致谢!转自:http://blog.sina.com.cn/s/blog_67299aec0100snk4.html   本篇可能不是非常深入,但是胜在清晰明了   FileStream对象表示在 ...

  5. c#StreamWriter,StreamReader类(主要用于文本文件访问)

    1.为什么要使用StreamReader或者StreamWriter 如果对文本文件需要读取一部分显示一部分则使用FileStream会有问题,因为可能FileStream会在读取的时候把一个汉字的字 ...

  6. 【基础巩固】文件流读写、大文件移动 FileStream StreamWriter File Path Directory/ ,m资料管理器(递归)

    C#获取文件名 扩展名 string fullPath = @"d:\test\default.avi"; string filename = Path.GetFileName(f ...

  7. StreamWriter StreamReader

    private void WriteLoginJsonData(object jsonData) { using (FileStream writerFileStream = new FileStre ...

  8. 利用FileStream实现多媒体文件复制

        利用FileStream实现多媒体文件复制的主要思路在于利用两个FileStream对象,一个读取字节,另一个对象写入字节既可.     涉及知识点: 1.通常我们操作的File类,FileS ...

  9. FileStream和BinaryReader,BinaryWriter,StreamReader,StreamWriter的区别

    FileStream对于在文件系统上读取和写入文件非常有用,FileStream缓存输入和输出,以获得更好的性能.FileStream对象表示在磁盘或网络路径上指向文件的流.这个类提供了在文件中读写字 ...

随机推荐

  1. python爬取网页图片

    # html:网页地址 def getImg2(html): soup = BeautifulSoup(html, 'html.parser') href_regex = re.compile(r'^ ...

  2. Python使用Flask框架,结合Highchart,自定义基本上算是最全的导出菜单了

    说用:引入export-data.js文件后,导出菜单中会自动显示出相应的导出选项,只需要在lang中换成中文名即可. 本实例除了包含系统自带的,还包括自定义的导出菜单等. html代码 <!D ...

  3. jq ajax请求error: Maximum call stack size exceeded

    原因是data中参数iconUrl这个变量未声明导致的.jq在内部循环时报错

  4. 常见的Redis问题?

    Redis的那些最常见面试问题[转] 1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据 ...

  5. 语法,if,while循环,for循环

    目录 一.语法 二.while循环 三.for循环 一.语法 if: if判断其实是在模拟人做判断.就是说如果这样干什么,如果那样干什么.对于ATM系统而言,则需要判断你的账号密码的正确性. if 条 ...

  6. Python基础(十)re模块

    Python基础阶段快到一段落,下面会陆续来介绍python面向对象的编程,今天主要是补充几个知识点,下面开始今天的内容. 一.反射 反射的作用就是列出对象的所有属性和方法,反射就是告诉我们,这个对象 ...

  7. HDU 5420 Victor and Proposition

    Victor and Proposition Time Limit: 6000ms Memory Limit: 524288KB This problem will be judged on HDU. ...

  8. poj 1986tarjan模板题

    #include<iostream> #include<vector> using namespace std; const int N=40010; int pre[N];/ ...

  9. HDU——3342 Legal or Not

    Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  10. iText输出中文的三种字体选择方式

    1.使用iTextAsian.jar中的字体    BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",Bas ...