G
Guest
Hi,
Is it possible to read a file in reverse and only get the last 100 bytes in
the file without reading the whole file from the begining? I have to get info
from files that are in the last 100 bytes of the file and some of these files
are 600Mb -1 GB in size. I am getting "outofMemory.." exceptions on the
largest files and the other files take "forever" to get the last 100 bytes.
This is the code I have currently that works with smaller files:
Dim fileData() As Byte
FilePath = "C:\Temp\1DD04336CA1A45CB81A89167048D2594.abk"
Try
Dim oFile As System.IO.FileInfo
oFile = New System.IO.FileInfo(FilePath)
Dim oFileStream As System.IO.FileStream = oFile.Open
_(IO.FileMode.Open, IO.FileAccess.Read)
Dim lBytes As Long = oFileStream.Length
ReDim fileData(lBytes)
Dim StartReadAt As Long = lBytes - 100
Dim StopReadAt As Long = 100
oFileStream.Read(fileData, StartReadAt, StopReadAt)
oFileStream.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
The problem with this code is an Array is created in the size of the file
resulting in upper bounds of maybe 200 000 000, so this is time consuming to
get the last 100 bytes.
Any idéas?
Thanks /Thomas
Is it possible to read a file in reverse and only get the last 100 bytes in
the file without reading the whole file from the begining? I have to get info
from files that are in the last 100 bytes of the file and some of these files
are 600Mb -1 GB in size. I am getting "outofMemory.." exceptions on the
largest files and the other files take "forever" to get the last 100 bytes.
This is the code I have currently that works with smaller files:
Dim fileData() As Byte
FilePath = "C:\Temp\1DD04336CA1A45CB81A89167048D2594.abk"
Try
Dim oFile As System.IO.FileInfo
oFile = New System.IO.FileInfo(FilePath)
Dim oFileStream As System.IO.FileStream = oFile.Open
_(IO.FileMode.Open, IO.FileAccess.Read)
Dim lBytes As Long = oFileStream.Length
ReDim fileData(lBytes)
Dim StartReadAt As Long = lBytes - 100
Dim StopReadAt As Long = 100
oFileStream.Read(fileData, StartReadAt, StopReadAt)
oFileStream.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
The problem with this code is an Array is created in the size of the file
resulting in upper bounds of maybe 200 000 000, so this is time consuming to
get the last 100 bytes.
Any idéas?
Thanks /Thomas