我正在尝试使用FileStream
将文件从目录复制到另一个目录并且工作正常,但在复制大文件时会抛出错误Arithmetic operation resulted in an overflow.
它无法复制大于20MB的文件。请问我是编程新手,你可以帮助我吗?
Private mCurrentFile As String = String.Empty
Public ReadOnly Property CurrentFile() As String
Get
Return mCurrentFile
End Get
End Property
Dim FS As FileStream
mCurrentFile = GetFileName(URL)
Dim wRemote As WebRequest
Dim bBuffer As Byte()
ReDim bBuffer(256)
Dim iBytesRead As Integer
Dim iTotalBytesRead As Integer
FS = New FileStream(Location, FileMode.Create, FileAccess.Write)
wRemote = WebRequest.Create(URL)
Dim myWebResponse As WebResponse = wRemote.GetResponse
RaiseEvent FileDownloadSizeObtained(myWebResponse.ContentLength)
Dim sChunks As Stream = myWebResponse.GetResponseStream
Do
iBytesRead = sChunks.Read(bBuffer, 0, 256)
FS.Write(bBuffer, 0, iBytesRead)
iTotalBytesRead += iBytesRead
If myWebResponse.ContentLength < iTotalBytesRead Then
RaiseEvent AmountDownloadedChanged(myWebResponse.ContentLength)
Else
RaiseEvent AmountDownloadedChanged(iTotalBytesRead)
End If
Loop While Not iBytesRead = 0 And dStop = False
sChunks.Close()
FS.Close()
Private Sub _Downloader_FileDownloadSizeObtained(ByVal iFileSize As Long) Handles _Downloader.FileDownloadSizeObtained
'FIRES WHEN WE HAVE GOTTEN THE DOWNLOAD SIZE, SO WE KNOW WHAT BOUNDS TO GIVE THE PROGRESS BAR
ProgressBar1.Value = 0
ProgressBar1.Maximum = CInt(iFileSize)
End Sub
错误抛出此处。
Private Sub _Downloader_AmountDownloadedChanged(ByVal iNewProgress As Long) Handles _Downloader.AmountDownloadedChanged
'FIRES WHEN MORE OF THE FILE HAS BEEN DOWNLOADED
ProgressBar1.Value = Convert.ToInt64(iNewProgress) '<-------------- Error throws here
Application.DoEvents()
End Sub
我不知道任何更大的类型可以处理大文件还是有其他方式?