读写二进制文件 VB.NET

前端之家收集整理的这篇文章主要介绍了读写二进制文件 VB.NET前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

需要引入命名空间

Imports System.IO

'二进制流 转文件
Public Function BinaryToFile(ByVal byTmp As Byte(),ByVal path As String) As Boolean
Dim fs As FileStream
Dim bwr As BinaryWriter

fs = New FileStream(path,FileMode.Create)
bwr = New BinaryWriter(fs)

bwr.Write(byTmp)
bwr.Flush()

bwr.Close()
fs.Close()
fs.Dispose()

Return True
End Function

'文件转二进制流,读取文件二进制流
Public Function FileToBinary(ByRef byTmp As Byte(),ByVal path As String) As Boolean
Dim fs As FileStream
Dim br As BinaryReader

fs = New FileStream(path,FileMode.Open,FileAccess.Read)
br = New BinaryReader(fs)

byTmp = br.ReadBytes(fs.Length)

br.Close()
fs.Close()
fs.Dispose()

Return True End Function

原文链接:https://www.f2er.com/vb/261437.html

猜你在找的VB相关文章