Re-using a filestream in a loop

  • Thread starter Thread starter simonc
  • Start date Start date
S

simonc

I want to make a loop to read data from a succession of binary files
(filepaths of the files are in a string array).

If I create a new filestream and from that a new binary reader before the
start of the loop how can I redefine the filestream to look at a different
file each time I go through the loop?

Grateful for advice
 
simonc said:
I want to make a loop to read data from a succession of binary files
(filepaths of the files are in a string array).

If I create a new filestream and from that a new binary reader before
the start of the loop how can I redefine the filestream to look at a
different file each time I go through the loop?

You can make a new instance for each loop iteration:

For Each f In files
Using br = New BinaryReader(New FileStream(f, FileMode.Open))
' do something with br
End Using
Next
 
Back
Top