好吧,先上图:

这里是TextReder类官方的解释:(http://msdn.microsoft.com/zh-cn/library/system.io.textreader.aspx)

<span class="sentence" data-guid="a33ef5a97279b93e7e764970d03d67a3" data-source="A derived class must minimally implement the Peek and Read methods to make a useful instance of TextReader. “>这里是Stream类官方的解释:(http://msdn.microsoft.com/zh-cn/library/system.io.stream.aspx)

<span class="sentence" data-guid="a33ef5a97279b93e7e764970d03d67a3" data-source="A derived class must minimally implement the Peek and Read methods to make a useful instance of TextReader. “>我们要使用的FileStream和streamreader这两个类。那好,我们再来看看他们MSDN是怎么描述这个类的吧!

<span class="sentence" data-guid="a33ef5a97279b93e7e764970d03d67a3" data-source="A derived class must minimally implement the Peek and Read methods to make a useful instance of TextReader. “>首先来看看FileStream(http://msdn.microsoft.com/zh-cn/library/system.io.filestream.aspx)类在MSDN上的描述如下:

<span class="sentence" id="mt62" data-guid="4a7313330f7cddf56672da12f414daf1" data-source="Use the FileStream class to read from, write to, open, and close files on a file system, as well as to manipulate other file-related operating system handles including pipes, standard input, and standard output.”>使用 FileStream 类对文件系统上的文件进行读取、写入、打开和关闭操作,并对其他与文件相关的操作系统句柄进行操作,如管道、标准输入和标准输出。 可以指定读写操作是同步还是异步。 <span class="sentence" id="mt64" data-guid="6b4465ca5858a31c6a5c3bdda46ca608" data-source="FileStream buffers input and output for better performance.”>FileStream 缓冲输入和输出以获得更好的性能。–部分内容以删简

<span class="sentence" data-guid="6b4465ca5858a31c6a5c3bdda46ca608" data-source="FileStream buffers input and output for better performance.”>再来看看StreamReader(http://msdn.microsoft.com/zh-cn/library/system.io.streamreader.aspx)类在MSDN上的描述如下:

<span class="sentence" id="mt36" data-guid="5c81b83a3802128ed37ac047fd2271f7" data-source="StreamReader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output.”>StreamReader 旨在以一种特定的编码输入字符,而 Stream 类用于字节的输入和输出。 <span class="sentence" id="mt37" data-guid="2e91aac8936e82286dc380b1fdda2b8e" data-source="Use StreamReader for reading lines of information from a standard text file.”>使用 StreamReader 读取标准文本文件的各行信息。

<span class="sentence" id="mt38" data-guid="0df443b9b8f7463efd3ca766288df032" data-source="StreamReader defaults to UTF-8 encoding unless specified otherwise, instead of defaulting to the ANSI code page for the current system.”>除非另外指定,StreamReader 的默认编码为 UTF-8,而不是当前系统的 ANSI 代码页。 UTF-8 可以正确处理 Unicode 字符并在操作系统的本地化版本上提供一致的结果。

<span class="sentence" id="mt40" data-guid="f8aad3204852d9f458b3b3afc027e810" data-source="By default, a StreamReader is not thread safe.”>默认情况下,StreamReader 不是线程安全的。 <span class="sentence" id="mt41" data-guid="318342281de58b7a3d2f66a85a0677a3" data-source="See TextReader.Synchronized for a thread-safe wrapper.”>有关线程安全包装的信息,请参见 TextReader.Synchronized。–<span class="sentence" id="mt64" data-guid="6b4465ca5858a31c6a5c3bdda46ca608" data-source="FileStream buffers input and output for better performance.”>部分内容以删简
<span class="sentence" data-guid="6b4465ca5858a31c6a5c3bdda46ca608" data-source="FileStream buffers input and output for better performance.”>
从这两个描述的对比来看我们就知道了FileStream主要是操作<span class="sentence" id="mt62" data-guid="4a7313330f7cddf56672da12f414daf1" data-source="Use the FileStream class to read from, write to, open, and close files on a file system, as well as to manipulate other file-related operating system handles including pipes, standard input, and standard output.”>文件系统上的文件,那么什么又是文件系统呢,按照我的理解就是存在于网络上的文件。

<span class="sentence" data-guid="4a7313330f7cddf56672da12f414daf1" data-source="Use the FileStream class to read from, write to, open, and close files on a file system, as well as to manipulate other file-related operating system handles including pipes, standard input, and standard output.”>那么StreamReader它只是<span class="sentence" id="mt37" data-guid="2e91aac8936e82286dc380b1fdda2b8e" data-source="Use StreamReader for reading lines of information from a standard text file.”>读取标准文本文件的各行信息,我的理解就是操作本地文本文件的内容。

<span class="sentence" data-guid="2e91aac8936e82286dc380b1fdda2b8e" data-source="Use StreamReader for reading lines of information from a standard text file.”>那好,我们已经认识了这两个文件是做什么的,那么我们才能知道在什么时候去使用。具体的使用整理后在贴出来。以便以后方便使用。

您可能感兴趣的文章:

  • C#文件和字节流的转换方法
  • C#实现获取文件夹大小的方法
  • C#实现解压GZip文件的方法
  • C#实现文件断点续传下载的方法
  • C#文件流进行压缩和解压缩的方法
  • C#通过DataSet读写xml文件的方法
  • C#对文件/文件夹操作代码汇总
  • C#控制台进行文件读写的方法
  • asp.net StreamReader 创建文件的实例代码
  • 解析StreamReader与文件乱码问题的解决方法
  • C#使用StreamReader读取文件的方法
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。