读写二进制文件 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

 

你可能感兴趣的:(.NET)