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. Jdk动态代理和CGLIB动态代理大比拼

    前言: 这2种动态代理算是老生常谈的吧,面试还是会经常问到的,下面做下分析: jdk动态代理: import java.lang.reflect.InvocationHandler; import j ...

  2. 配置Django中数据库读写分离

    django在进行数据库操作的时候,读取数据与写数据(曾.删.改)可以分别从不同的数据库进行操作 修改配置文件: DATABASES = { 'default': { 'ENGINE': 'djang ...

  3. 零基础入门学习Python(26)--字典:当索引不好用时2

    知识点 删除字典元素 能删单一的元素也能清空字典,清空只需一项操作. 显示删除一个字典用del命令,如下: >>> dict1 = {'a':1,'b':2,'c':3} >& ...

  4. webdriver学习笔记(一):webdrive脚本打开firefox浏览器,报“AttributeError: module 'selenium.webdriver' has no attribu

    按照网上提供的方法: 下载geckodriver之后解压缩到 Firefox安装目录 下 添加 Firefox安装目录 到 系统变量Path 重启pycharm 照此步骤执行后,仍然报同样的错.折腾了 ...

  5. PHP学习笔记<参数的传递>

    简单的例子说明参数在PHP文件之间的传递(有两个PHP文件在index.php文件上点击链接,在跳转的时候,依据参数的不同在neirong.php文件中显示不同的内容) inde.php的内容如下: ...

  6. Flask组件:flask-sqlalchemy & flask-script & flask-migrate

    flask-sqlalchemy组件 项目目录结构: flask目录 # 项目名 |--- flaskdir |--- static # 静态文件 |--- templates # 模板 |--- m ...

  7. linux 常见名词及命令(五)

    计划任务服务之一次性任务: at <时间> 安排一次性任务 atq 或at -l 查看任务列表 at -c 序号 预览任务与设置环境 atrm 序号 删除任务 安排任务示例: 在23:30 ...

  8. webview的设置

    设置支持js: webView.getSettings().setJavaScriptEnabled(true); 设置无图模式: webView.getSettings().setBlockNetw ...

  9. Webstrom打开太慢

    让webstrom将安装包目录屏蔽,settings-搜索file types-在ignore file and folders加入node_modules目录,操作方式如下:

  10. 用ReentrantLock和Condition实现生产者和消费者模式

    前面一篇文章<wait.notify应用场景(生产者-消费者模式)>是一种生产者消费者模式实现,今晚这是Lock方式实现,下面是源码: 生产者代码: /** * 生产者 * * @auth ...