FileStream vs/differences StreamWriter?

发布时间:2017-7-1 11:43:25编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"FileStream vs/differences StreamWriter? ",主要涉及到FileStream vs/differences StreamWriter? 方面的内容,对于FileStream vs/differences StreamWriter? 感兴趣的同学可以参考一下。

https://stackoverflow.com/questions/4963667/filestream-vs-differences-streamwriter

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.  


上一篇:Deep Q-Network 学习笔记(五)—— 改进③:Prioritized Replay 算法
下一篇:IIS虚拟目录与UNC路径权限初探

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款