序列化对象并将其写入磁盘

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了序列化对象并将其写入磁盘相关的知识,希望对你有一定的参考价值。

Serializes any object and writes it to the specified location on the disk.

Example:


Dim obj As DataTable
'save obj to disk
SerializeToFile(filepath, obj)
'to read it back, use DirectCast
Dim obj2 As DataTable = DirectCast(My.Computer.FileSystem.ReadAllBytes(filepath), DataTable)
  1. 'serialize an object to a file
  2. Public Shared Sub SerializeToFile(ByVal path As String, ByVal data As Object)
  3. Try
  4. Dim BF As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
  5. Dim MS As New System.IO.MemoryStream()
  6. BF.Serialize(MS, data)
  7. My.Computer.FileSystem.WriteAllBytes(path, MS.GetBuffer(), False)
  8. Catch ex As Exception
  9. Throw ex
  10. End Try
  11. End Sub

以上是关于序列化对象并将其写入磁盘的主要内容,如果未能解决你的问题,请参考以下文章

从 BigQuery 读取数据并将其写入云存储上的 avro 文件格式

Java 序列化

AES 填充并将密文写入磁盘文件

qt c ++中反序列化地图的大小增加

创建内存积累的 AFHTTPRequestOperations 队列

java 序列化 - 持久化类定义