打印本文 打印本文 关闭窗口 关闭窗口
VB 二进制块读写类模块(第一版)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2048  更新时间:2009/4/23 15:41:25  文章录入:mintao  责任编辑:mintao
nbsp; nActual = m_cFileRead.ReadBlock(lpBuf, BUFFER_SIZE)
    m_cFileWrite.WriteBlock lpBuf, nActual
Loop Until nActual < BUFFER_SIZE ''''当实际读取字节数小于缓冲区大小的时候,就不需要再读啦,已读完啦

m_cFileRead.CloseFile
m_cFileWrite.CloseFile

MsgBox "OK! total time:" & Timer - tmr
End Sub

Private Sub Command2_Click()
Const BUFFER_SIZE = 1
Dim nActual As Long
Dim aBuf(0 To BUFFER_SIZE - 1) As Byte
Dim tmr As Single

tmr = Timer

If Not m_cFileRead.OpenBinary(Text1.Text) Then MsgBox "打开文件失败!" & Text1.Text
If Not m_cFileWrite.OpenBinary(Text2.Text) Then MsgBox "打开文件失败!" & Text2.Text

Do
    nActual = m_cFileRead.ReadBlock(VarPtr(aBuf(0)), BUFFER_SIZE)
    m_cFileWrite.WriteBlock VarPtr(aBuf(0)), nActual
Loop Until nActual < BUFFER_SIZE ''''当实际读取字节数小于缓冲区大小的时候,就不需要再读啦,已读完啦

m_cFileRead.CloseFile
m_cFileWrite.CloseFile

MsgBox "OK! total time:" & Timer - tmr
End Sub

Private Sub Command3_Click()
Const BUFFER_SIZE = 40960 * 2
Dim nActual As Long
Dim aBuf(0 To BUFFER_SIZE - 1) As Byte
Dim tmr As Single
Dim lFileLen As Long
Dim iFileNum As Integer
Dim k As Long

tmr = Timer

If Not m_cFileRead.OpenBinary(Text1.Text) Then MsgBox "打开文件失败!" & Text1.Text
If Not m_cFileWrite.OpenBinary(Text2.Text) Then MsgBox "打开文件失败!" & Text2.Text
lFileLen = m_cFileRead.FileLength
iFileNum = m_cFileRead.FileNumber

k = 0
Do
    k = k + 1
    If k = 10 Then
        k = 0
        pb1.Value = 100 * (Seek(iFileNum) / lFileLen)
        DoEvents
    End If
    nActual = m_cFileRead.ReadBlock(VarPtr(aBuf(0)), BUFFER_SIZE)
    m_cFileWrite.WriteBlock VarPtr(aBuf(0)), nActual
Loop Until nActual < BUFFER_SIZE ''''当实际读取字节数小于缓冲区大小的时候,就不需要再读啦,已读完啦

m_cFileRead.CloseFile
m_cFileWrite.CloseFile

MsgBox "OK! total time:" & Timer - tmr
End Sub

Private Sub Command4_Click()
Dim sPass As String
sPass = InputBox("请输入密码。")
Dim cLogi As New CLogistic
cLogi.Pass = sPass

Const BUFFER_SIZE = 4096
Dim nActual As Long
Dim aBuf(0 To BUFFER_SIZE - 1) As Byte
Dim tmr As Single
Dim lFileLen As Long
Dim iFileNum As Integer
Dim k As Long

tmr = Timer

If Not m_cFileRead.OpenBinary(Text1.Text) Then MsgBox "打开文件失败!" & Text1.Text
If Not m_cFileWrite.OpenBinary(Text2.Text) Then MsgBox "打开文件失败!" & Text2.Text
lFileLen = m_cFileRead.FileLength
iFileNum = m_cFileRead.FileNumber

k = 0
Do
    k = k + 1
    If k = 10 Then
        k = 0
        pb1.Value = 100 * (Seek(iFileNum) / lFileLen)
        DoEvents
    End If
    nActual = m_cFileRead.ReadBlock(VarPtr(aBuf(0)), BUFFER_SIZE)
    cLogi.EncBlock aBuf, nActual
    m_cFileWrite.WriteBlock VarPtr(aBuf(0)), nActual
Loop Until nActual < BUFFER_SIZE ''''当实际读取字节数小于缓冲区大小的时候,就不需要再读啦,已读完啦

m_cFileRead.CloseFile
m_cFileWrite.CloseFile

MsgBox "OK! total time:" & Timer - tmr

End Sub

Private Sub Command5_Click()
If Not m_cFileRead.OpenBinary(Text1.Text) Then MsgBox "打开文件失败!" & Text1.Text
m_cFileRead.CloseFile

If Not m_cFileRead.OpenBinary(Text1.Text) Then MsgBox "打开文件失败!" & Text1.Text
m_cFileRead.CloseFile

If Not m_cFileWrite.OpenBinary(Text2.Text) Then MsgBox "打开文件失败!" & Text2.Text
m_cFileWrite.CloseFile
If Not m_cFileWrite.OpenBinary(Text2.Text) Then MsgBox "打开文件失败!" & Text2.Text
m_cFileWrite.CloseFile

End Sub

''''---------------------------------------------------------------------------------------------------------------------------

''''-------------------------------------------------------------------------------------------------------------------------''''

完整的VB工程文件可从这里下载

http://lqweb.nease.net/mycode/FileReadBlockFileWriteBlock.zip

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口