什么是的StreamWriter和的BinaryWriter之间的区别? [英] what's the difference between a streamwriter and a binarywriter?

查看:572
本文介绍了什么是的StreamWriter和的BinaryWriter之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的混淆了我,说我要一个整数保存到一个文件中,INT X = 56,的BinaryWriter采用ASCII等效56表示在内存
00000000 00000000 00000000 00111000,具体做法是:空空空8,并将其写入文件?我对么?有人可以解释如何将这些twofunction当我应该使用每个人?即时通讯使用C#顺便说一句。 thanx提前!

this really confuses me, say i want to save an integer into a file, int x=56, the binarywriter takes the ascii equivalent of the representation of 56 in memory 00000000 00000000 00000000 00111000 , which would be : null null null 8 and write it to the file? am i correct? can someone explain how those twofunction and when should i use each of them? im using c# btw. thanx in advance!

推荐答案

从MSDN页面的的StreamWriter 的BinaryWriter 你可以清楚地看到差异:

From the MSDN pages for StreamWriter and BinaryWriter you can clearly see the differences:

StreamWriter的:

StreamWriter:

实现为在一个特定的
编码写入
字符流的的TextWriter

Implements a TextWriter for writing characters to a stream in a particular encoding.

的BinaryWriter:

BinaryWriter:

在二至
流写入基本类型和支持写入
A特定的编码字符串。

Writes primitive types in binary to a stream and supports writing strings in a specific encoding.

第一个写东西的文本,二进制第二写入,<一个HREF =http://en.wikipedia.org/wiki/Little_endian>小尾数,所以 INT X = 56 将被写入 00111000 00000000 00000000 00000000

The first one writes things as text, the second writes in binary, little endian, so int x = 56 would be written 00111000 00000000 00000000 00000000.

这篇关于什么是的StreamWriter和的BinaryWriter之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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