File.OpenText.ReadToEnd and File Handles

  • Thread starter Thread starter Assaf Rozenblatt
  • Start date Start date
A

Assaf Rozenblatt

Hi,

When reading in the contents of a text file without creating a new
file object, like so:

Buffer = IO.File.OpenText(PathToFile).ReadToEnd

Does .Net internally close the file or does it remain open?
 
Assaf Rozenblatt said:
When reading in the contents of a text file without creating a new
file object, like so:

Buffer = IO.File.OpenText(PathToFile).ReadToEnd

Does .Net internally close the file or does it remain open?

It remains open until the stream is closed. If you don't close the stream
yourself, then the handle will be freed when the GC "finalizes" the object.
 

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

Back
Top