VS的FileStream /差异的StreamWriter? [英] FileStream vs/differences StreamWriter?

查看:115
本文介绍了VS的FileStream /差异的StreamWriter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:



什么是的FileStream和StreamWriter之间的不同之处DOTNET



什么情况下,你应该使用它?什么是他们的优势和劣势?



是否有可能将这两个合并成一个?


解决方案

什么是DOTNET的FileStream和StreamWriter之间有什么不同?




A 的FileStream 。像所有的流只用涉及的byte [] 数据。



A 的StreamWriter 的TextWriter ,一个流的装饰。一个TextWriter的转换或编码像字符串或字符为字节[] 文本数据,然后将其写入到链接




什么情况下,你应该使用它?什么是他们的优势和劣势?




您使用裸露的FileStream当你有字节[] 数据。您添加的StreamWriter 当你想要写的文字。




是否有可能这两个成一个结合?




是的。你总是需要一个流来创建的StreamWriter。 System.IO.File.CreateText(路径)将联合创建它们,然后你只需要Dispose()方法外作家。


Question:

What is different between FileStream and StreamWriter in dotnet?

What context are you supposed to use it? What is their advantage and disadvantage?

Is it possible to combine these two into one?

解决方案

What is different between FileStream and StreamWriter in dotnet?

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

A 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.

这篇关于VS的FileStream /差异的StreamWriter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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