什么是StreamReader的目的时Stream.Read()是否存在? [英] What is the purpose of StreamReader when Stream.Read() exists?

查看:187
本文介绍了什么是StreamReader的目的时Stream.Read()是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一直缠着我。我知道的是一个抽象类,因此不能被实例化,但它有一个由它派生的类。为什么有的StreamReader 类和 Stream.Read()方式(反之为诗的StreamWriter Stream.Write() )?您可以写信给使用3个百万个不同的方法,一个文本文件,这是相当令人沮丧试图让我的头周围所有这些不同的类型和方法在 System.IO 命名空间。我发现对于有关此特殊情况下,作者和读者对象或派生的流对象本身,而没有任何的区别问题和答案。

This has been bugging me. I know Stream is an abstract class and therefore can't be instantiated but it has classes that are derived from it. Why is there a StreamReader class and a Stream.Read() method (and vice verse for StreamWriter and Stream.Write())? You can write to a text file using 3 million different methods and it's rather frustrating trying to get my head around all of these different types and methods in the System.IO namespace. I found questions and answers regarding the differences between the writer and reader objects or the derived stream objects themselves but nothing regarding this particular case.

推荐答案

的TextReader (其中的StreamReader 源自)适用于字符串。 适用于字节。文本和字节之间的转换是由编码执行。

TextReader (which StreamReader is derived from) works with strings. Stream works with bytes. The conversion between text and bytes is performed by an Encoding.

选择是否基于内容的正确类文件文本或二进制。

Choose the right class based on whether the contents of your file text or binary.

了解区别是很重要的文本和字节之间

这篇关于什么是StreamReader的目的时Stream.Read()是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆