我正在关注序列化大文件块的示例here。不管怎么说是序列化的新手,我现在已经丢失了传递给我的Serialize方法的参数。由于OOM异常,我搁置了我使用yesterday的方法。非常感谢您的帮助。
Public Shared Sub ReadAndProcessLargeFile(theFilename As String, ByVal obj As LocalDBObject, Optional whereToStartReading As Long = 0)
Dim bf As New BinaryFormatter() ' Create a binary formatter for this stream.
Using fileStram As New FileStream(theFilename, FileMode.Open, FileAccess.Read)
Dim buffer As Byte() = New Byte(fileStram.Length - 1) {}
fileStram.Seek(whereToStartReading, SeekOrigin.Begin)
Dim bytesRead As Integer = fileStram.Read(buffer, 0, buffer.Length)
While bytesRead > 0
bytesRead = fileStram.Read(buffer, 0, buffer.Length - 1)
'It is here where I am now lost. What parameters do I supply to my Serialize method below
bf.Serialize()
End While
End Using
End Sub
答案 0 :(得分:0)
嗯,该代码只是没有序列化任何东西,序列化你应该这样做:
Public Shared Sub Serialize(theFilename As String, ByVal obj As LocalDBObject)
Dim bf As New BinaryFormatter() ' Create a binary formatter for this stream.
Using fileStram As File.Create(theFilename)
bf.Serialize(fileStram, obj);
End Using
End Sub
但我怀疑这不是你想要的,除非你解释得更好,你的问题很难理解你想要达到的目标。