Search code examples
vb.netfile.readalllines

How to best and most efficiently Split files into vb.net


Say I have a 5 GB file. I want to split it in the following way.

First 100 MB is on the file

The rest go some reserve file

I do not want to use readalllines kind of function because it's too slow for large files.

I do not want to read the whole file to the memory. I want the program to handle only a medium chunk of data at a time.


Solution

  • You may use BinaryReader class and its method to read file in chunks.

    Dim chunk() As Byte
    chunk = br.ReadBytes(1024)