StreamReader / StreamWriter与System.IO.File。*? [英] StreamReader / StreamWriter vs System.IO.File.*?

查看:91
本文介绍了StreamReader / StreamWriter与System.IO.File。*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Visual C#2005代码片段,并且文件处理的片段

使用StreamReader和StreamWriter,而不是

System.IO.File。*。 VB 2005代码片段不使用这些。为什么

他们建议使用这些类而不是基本的

文件方法?他们更好吗?我认为代码片段应该是

以简单/简单的方式显示内容。


你们怎么想?

学习读/写文件时,初学者应该学会做什么?


Zytan

I have installed the Visual C# 2005 Code Snippets, and the snippets
for file handling use StreamReader and StreamWriter, instead of
System.IO.File.*. VB 2005 code snippets don''t use these. Why are
they suggesting the use of these classes instead of the fundamental
File methods? Are they better? I thought code snippets were supposed
show things in the easy / simple way.

What do you guys think? What should a beginner learn to do when
learning to read / write files?

Zytan

推荐答案

片段

用于文件处理使用StreamReader和StreamWriter
for file handling use StreamReader and StreamWriter



他们甚至使用using语句!这很难很快掌握

(特别是当文档使用在使用语句块的

之前创建的资源显示它时,这很奇怪,因为它应该是

在块的末尾破坏该对象,但是如果对象在使用语句之后仍然在范围内,它怎么能这样做

$ / b
阻止!?)

And they even use the using-statement! Which is hard to grasp quickly
(especially when the docs show it using a resource created before the
using statement block, which is strange since it is supposed to
destruct that object at the end of the block, but how can it do this
when the object it is *still in scope* after the using statement
block!?)


我认为代码片段应该是

以简单/简单的方式显示内容。
I thought code snippets were supposed
show things in the easy / simple way.



因此,这些片段肯定不是最简单的方式。


Zytan

So, these snippets are certainly not the easiest way.

Zytan


Zytan写道:
Zytan wrote:

我已经安装了Visual C#2005代码片段和片段

for文件处理使用StreamReader和StreamWriter,而不是

System.IO.File。*。 VB 2005代码片段不使用这些。为什么

他们建议使用这些类而不是基本的

文件方法?他们更好吗?我认为代码片段应该是

以简单/简单的方式显示内容。


你们怎么想?

学习读/写文件时,初学者应该学会做些什么?
I have installed the Visual C# 2005 Code Snippets, and the snippets
for file handling use StreamReader and StreamWriter, instead of
System.IO.File.*. VB 2005 code snippets don''t use these. Why are
they suggesting the use of these classes instead of the fundamental
File methods? Are they better? I thought code snippets were supposed
show things in the easy / simple way.

What do you guys think? What should a beginner learn to do when
learning to read / write files?



我没有代码片段,但我认为你可以使用

以下经验法则:

*二进制文件流

* Writer / *文本文件阅读器(忽略BinaryReader / BinaryWriter)


* Writer / *阅读器是*流上的附加功能。


Arne

I do not have code snippets, but I think you can use
the following rule of thumb:

*Stream for binary files
*Writer/*Reader for text files (ignoring BinaryReader/BinaryWriter)

*Writer/*Reader are additional functionality on top of *Stream.

Arne


Zytan写道:
Zytan wrote:

>文件处理的片段
使用StreamReader和StreamWriter
>the snippets
for file handling use StreamReader and StreamWriter



他们甚至使用使用-声明!这很难很快掌握

(特别是当文档使用在使用语句块的

之前创建的资源显示它时,这很奇怪,因为它应该是

在块的末尾破坏该对象,但是如果对象在使用语句之后仍然在范围内,它怎么能这样做

$ / b
block!?)


And they even use the using-statement! Which is hard to grasp quickly
(especially when the docs show it using a resource created before the
using statement block, which is strange since it is supposed to
destruct that object at the end of the block, but how can it do this
when the object it is *still in scope* after the using statement
block!?)



在使用块结束时,调用Dispose方法

将释放所有非托管资源。这不是

destructed。


Arne

At the end of the using block the Dispose method is called
which will release all unmanaged resources. It is not
"destructed".

Arne


这篇关于StreamReader / StreamWriter与System.IO.File。*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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