Re-using a filestream in a loop

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
 
A

Andrew Morton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top