将文件转换为二进制文件的VB代码
将任何文件转换为二进制文件的VB代码,例如把一个MP3,程序(exe),word(doc)文件,视频文件,图片(jpg.gif)等等,将他们转换为二进制数据,因为小弟是新...
将任何文件转换为二进制文件的VB代码,例如把一个MP3,程序(exe),word(doc)文件,视频文件,图片(jpg.gif)等等,将他们转换为二进制数据,因为小弟是新手,所以请在旁边写上说明.谢谢!!
展开
2013-07-31
展开全部
''' <summary>
''' 将AE中实现了IPersistStream接口的对象序列化为二进制文件
''' </summary>
''' <param name="pObject">对象</param>
''' <param name="pFilePath">文件名全路径(形如:“C:\file.blb”)</param>
''' <remarks></remarks>
Sub WriteObject(ByVal pFilePath As String, ByVal pObject As Object)
If Not TypeOf pObject Is IPersistStream Then
MessageBox.Show("该对象不支持序列化!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim pMemoryBlobStream As IMemoryBlobStream = New MemoryBlobStream
Dim pObjectStream As IObjectStream = New ObjectStream
pObjectStream.Stream = pMemoryBlobStream
Dim pPersistStream As IPersistStream = pObject
pPersistStream.Save(pObjectStream, True)
Try
pMemoryBlobStream.SaveToFile(pFilePath)
Catch ex As Exception
MessageBox.Show("序列化文件路径不合法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
''' <summary>
''' 从序列化文件中读取对象(反序列化)
''' </summary>
''' <param name="pObject">对象</param>
''' <param name="pFilePath">文件名全路径(形如:“C:\file.blb”)</param>
''' <remarks></remarks>
Sub ReadObject(ByVal pFilePath As String, ByRef pObject As Object)
If Not TypeOf pObject Is IPersistStream Then
MessageBox.Show("该对象不支持序列化!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If Not System.IO.File.Exists(pFilePath) Then
MessageBox.Show("序列化文件不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim pMemoryBlobStream As IMemoryBlobStream = New MemoryBlobStream
pMemoryBlobStream.LoadFromFile(pFilePath)
Dim pObjectStream As IObjectStream = New ObjectStream
pObjectStream.Stream = pMemoryBlobStream
Dim pPersistStream As IPersistStream = pObject
pPersistStream.Load(pObjectStream)
End Sub
''' 将AE中实现了IPersistStream接口的对象序列化为二进制文件
''' </summary>
''' <param name="pObject">对象</param>
''' <param name="pFilePath">文件名全路径(形如:“C:\file.blb”)</param>
''' <remarks></remarks>
Sub WriteObject(ByVal pFilePath As String, ByVal pObject As Object)
If Not TypeOf pObject Is IPersistStream Then
MessageBox.Show("该对象不支持序列化!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim pMemoryBlobStream As IMemoryBlobStream = New MemoryBlobStream
Dim pObjectStream As IObjectStream = New ObjectStream
pObjectStream.Stream = pMemoryBlobStream
Dim pPersistStream As IPersistStream = pObject
pPersistStream.Save(pObjectStream, True)
Try
pMemoryBlobStream.SaveToFile(pFilePath)
Catch ex As Exception
MessageBox.Show("序列化文件路径不合法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
''' <summary>
''' 从序列化文件中读取对象(反序列化)
''' </summary>
''' <param name="pObject">对象</param>
''' <param name="pFilePath">文件名全路径(形如:“C:\file.blb”)</param>
''' <remarks></remarks>
Sub ReadObject(ByVal pFilePath As String, ByRef pObject As Object)
If Not TypeOf pObject Is IPersistStream Then
MessageBox.Show("该对象不支持序列化!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If Not System.IO.File.Exists(pFilePath) Then
MessageBox.Show("序列化文件不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim pMemoryBlobStream As IMemoryBlobStream = New MemoryBlobStream
pMemoryBlobStream.LoadFromFile(pFilePath)
Dim pObjectStream As IObjectStream = New ObjectStream
pObjectStream.Stream = pMemoryBlobStream
Dim pPersistStream As IPersistStream = pObject
pPersistStream.Load(pObjectStream)
End Sub
2013-07-31
展开全部
将文件转换为二进制文件的VB代码?
任何文件在打开的时候都可以以二进制的方式打开.只需要在打开的时候选取适当的IO类就是了.
任何文件在打开的时候都可以以二进制的方式打开.只需要在打开的时候选取适当的IO类就是了.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-31
展开全部
说明书上不是有的吗?如果说没有的话我再打给你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询