Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I read a record from a file.


It reads and opens a stream.

Should Read not close its stream after reading, like ReadList does?

share|improve this question

closed as not a real question by Dr. belisarius, Simon Woods, Oleksandr R., Yves Klett, Artes Apr 8 '13 at 17:37

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

ReadList reads the whole content of a file, so it makes sense to close it afterwards, while Read only reads the next entry in the file (be it a number, line, record, whatever). This is by design. – István Zachar Apr 8 '13 at 14:08
Also note that ReadList only closes the stream afterwards if it was closed to begin with. I think you should regard the ReadList auto-closing behaviour as a convenient shortcut rather than "the way it should be". – Simon Woods Apr 8 '13 at 14:33

No, it should not. Often the point of having streams (for files) in the first place is so that the file is not constantly re-opened and closed.

share|improve this answer
No doubts. . .Where I point to here is using Read to read one element of a file not a stream. . .Even the fact that Read is not intendet to read from a file, it does it. . .And it does it correct. And while doing so it opens a stream. . .My impression is it should at least give a hint you are doing something wrong. . .Or close that opened stream after reading. – Hp Radojewski Schäfer Von Apr 9 '13 at 8:10
@HpR You will note that I did not vote to close this answer as I felt it was valid question. The community might have a kinder response to your questions if you showed interest in properly participating; as it stands you have voted only a few times and Accepted only two answers. Why do you ignore my (and other) requests for you to participate in these ways? – Mr.Wizard Apr 9 '13 at 11:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.