按指定数量字节分块读取文件
发布时间:2020-12-17 08:00:00 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 Option ExplicitPrivate Const OFS_MAXPATHNAME = 128Private Type OFSTRUCTcBytes As BytefFixedDisk As BytenErrCode As IntegerReserved1 As Integ
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 Option Explicit Private Const OFS_MAXPATHNAME = 128 Private Type OFSTRUCT cBytes As Byte fFixedDisk As Byte nErrCode As Integer Reserved1 As Integer Reserved2 As Integer szPathName(OFS_MAXPATHNAME) As Byte End Type Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String,lpReOpenBuff As OFSTRUCT,ByVal wStyle As Long) As Long Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long,ByVal lDistanceToMove As Long,lpDistanceToMoveHigh As Long,ByVal dwMoveMethod As Long) As Long Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long,lpFileSizeHigh As Long) As Long Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long,lpBuffer As Any,ByVal nNumberOfBytesToRead As Long,lpNumberOfBytesRead As Long,ByVal lpOverlapped As Any) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Const OF_READ = &H0 Private Const FILE_SHARE_READ = &H1 Private Const MAXLONG = &H7FFFFFFF Private Function ReadBlocks(filePath As String) As Boolean On Error GoTo Err Dim fHandle As Long Dim OF As OFSTRUCT fHandle = OpenFile(filePath,OF,OF_READ) If fHandle <> -1 Then Dim nSize As Long nSize = GetFileSize(fHandle,0) If nSize > 0 Then Dim Rtn As Long,filePos As Long Rtn= MAXLONG/16 ReDim bBytes(Rtn - 1) As Byte Do While Rtn = Len(bBytes(0)) SetFilePointer hFile,filePos,FILE_BEGIN ReadFile hFile,bBytes(0),Rtn,0 filePos= filePos+Rtn Loop ReadBlocks = True End If CloseHandle fHandle End If If Err Then Err.Clear ReadBlocks = False End If Exit Function Err: CloseHandle fHandle ReadBlocks = False End Sub 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |