[Newbies] Oponing a file twice
johnps11 at bigpond.com
johnps11 at bigpond.com
Thu Jul 5 12:53:14 UTC 2007
Just as I was thinking I was getting a handle on this I'm terribly
confused...
a _ FileStream fileNamed: 'readme.txt'.
gives me a stream an the file.
b _ FileStream fileNamed: 'readme.txt'.
gives me nil
a _ nil.
a _ FileStream fileNamed: 'readme.txt'.
a is still nil
It seems that the only way I can reopen this file is to
Smalltalk garbageCollect.
Now if I simply wanted to have two references to the file I could just
b _ a copy.
But what if I open a stream on a file, then reuse my variable, then
sometime later want to use that file again? Do I have to explicitly
perform garbage collection? That seems very wrong. Do I have to keep a
hold of all references to files and their filenames if I think I _might_
need that file again? That also seems very wrong.
Scenario:
...
some code
a _ FileStream fileNamed: 'readme.txt'.
some more code
...
a _ result of something
...
even more code
b _ FileStream fileNamed: 'readme.txt'.
I've looked at FileStream, StandardFileStream and MultiByteFileStream for
2 days now and am none the wiser (not quite true, I've learned you can
send Squeak into lala land by putting 'self halt' inside
FileStream>>fileNamed: and then getting any error at all... the debugger
seems to open a stream that opens a debugger that opens a stream that
opens a debugger etc etc)
What am I missing (I assume I'm overlooking something really simple)?
Thanks,
John
More information about the Beginners
mailing list