BinaryWriter和BinaryFormatter.Serialize之间的区别? [英] Difference between BinaryWriter and BinaryFormatter.Serialize?

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

问题描述

我是对象序列化的新手,在学习如何使用 BinaryFormatter 读写文件(反序列化和序列化)的过程中,我遇到了 BinaryReader BinaryWriter ,它们似乎在做同样的事情.

I'm new to object serialization, and in the course of my learning how to read from and write to a file (deserialize and serialize) using BinaryFormatter, I came across BinaryReader and BinaryWriter, which seemed to be doing the same thing.

BinaryFormatter.Serialize() BinaryWriter 之间是否存在细微差别?还是 BinaryWriter 只是一种更紧凑的方式来执行与 BinaryFormatter.Serialize()相同的动作?

Is there some subtle difference between BinaryFormatter.Serialize() and BinaryWriter? Or is BinaryWriter just a more compact way performing the the same action as BinaryFormatter.Serialize()?

推荐答案

BinaryWriter 用于将二进制类型的原始类型写入流,并支持以特定编码写入字符串. BinaryFromatter 负责将整个对象或连接的对象图序列化为二进制格式.因此,我想您可以说 BinaryWriter 是一种更基本的形式,例如 BinaryFormatter .

BinaryWriter is used to write primitive types in binary to a stream and supports writing strings in a specific encoding. BinaryFromatter is responsible for serializing an entire object or graph of connected objects into binary format. So, I suppose you can say BinaryWriter is a much more elementary form of something like BinaryFormatter.

我在这里获得此信息: BinaryWriter & BinaryFormatter

I got this information here: BinaryWriter & BinaryFormatter

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

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