如何用VB读写二进制文件?

解决方案 »

  1.   

    Dim mFileSize As Long
    Dim arrByte() As Byte
    Private Sub Command1_Click()
    '读
        Dim mHandle
        mHandle = FreeFile
        Open "c:\1.exe" For Binary As #mHandle
        mFileSize = LOF(mHandle)
        ReDim arrByte(1 To mFileSize)
        Get #mHandle, , arrByte
        Close mHandle
        
    '写    Open "c:\文件名.exe" For Binary As #1
        Put #1, , arrByte
        Close #1
    End Sub
      

  2.   


    Private Sub Command1_Click()       Dim FFile as Integer
        Dim a() as Byte
        Dim FLen as Long
       
        FLen=FileLen("1.bmp")
        ReDim a(FLen-1) as Byte
     
        FFile = FreeFile
        Open "1.bmp" For Binary As FFile
            Get #mFFile,1 , a
        Close FFile
        
        FFile = FreeFile
        Open "2.bmp" For Binary As FFile
        Put FFile, 1, a
        Close FFile
    End Sub