怎样文件中读取指定字节?
比如一个文件有900字节,我需要分三次读取,第1次200字节,第二次400字节,第三次300字节,怎么做的??
[解决办法]
dim fdata() as byte
open "e:\1.dat " for binary as #1
redim fdate(200-1)
get #1,1,fdata
redim fdate(400-1)
get #1,,fdata
redim fdate(300-1)
get #1,,fdata
close #1
[解决办法]
Dim aChunkSizes() as Byte
Dim readRtn as long
'hFile 是你的文件handle,用CreateFile API得到
SetFilePointer hFile, 0&, 0&, 0&
ReDim aChunkSizes(0 To 199)
ReadFile hFile, aChunkSizes(0), 200, readRtn, ByVal 0&
If readRtn=200 then
Debug.Print "Read First part successfully "
'你的后续处理程序在这里处理
Else
CloseHandle hFile
Exit Sub
End If
ReDim aChunkSizes(0 To 399)
ReadFile hFile, aChunkSizes(0), 400, readRtn, ByVal 0&
If readRtn=400 then
Debug.Print "Read 2nd part successfully "
'你的后续处理程序在这里处理
Else
CloseHandle hFile
Exit Sub
End If
ReDim aChunkSizes(0 To 299)
ReadFile hFile, aChunkSizes(0), 300, readRtn, ByVal 0&
If readRtn=300 then
Debug.Print "Read Last part successfully "
'你的后续处理程序在这里处理
Else
CloseHandle hFile
Exit Sub
End If
If Not hFile = 0& then CloseHandle hFile
[解决办法]
对于二进制打开方式,用seek方法就可以定位,这是VB提供的