VS的FileStream /差异的StreamWriter? [英] FileStream vs/differences 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 aStream
. Like all Streams it only deals withbyte[]
data.A
StreamWriter
is aTextWriter
, a Stream-decorator. A TextWriter converts or encodes Text data like string or char tobyte[]
and then writes it to the linkedStream
.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 aStreamWriter
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屋!