(NEWBIE) FileStream help??

Norton, Chris chrisn at Kronos.com
Sat Apr 29 02:05:34 UTC 2000


Hi James!

Welcome to Squeak!  :-)

You've just discovered that Smalltalk dialects are not all the same.  I got
curious about the differences myself, so I did a bit of experimenting.  If
you search for implementors of nextWord, you'll quickly discover that this
method is implemented by PositionableStream.  It answers the next two bytes
from the receiver as an Integer.  Of course, this is not what you wanted.
Then next thing you'll find is that PositionableStream's nextString method
won't work either (because this method requires information up front about
how long the string will be!).  You'd think that there was a simpler
solution to this general problem (and there probably is), but I couldn't
find it.

The following class demonstrates a solution to your example.  Class Food has
a class method foodsFromPathName: which does what you're interested in.
This may not be the optimal solution, but it'll get you going...

Cheers,

---==> Chris

PS>  File in the class, then in a workspace execute:  Food
printFoodsInTranscriptFromFile: 'c:\squeak\vtbls.txt'.
PPS>  You'll see that I've put the code that reads from the file stream in
an ensure block.  It is always a good idea to do this, just in case you have
an error in your code.  This will prevent you from generating dangling file
handles (I hate it when they do that!  ;-).

 <<Example-Food.st>> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Example-Food.st
Type: application/octet-stream
Size: 2569 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20000428/bf64b174/Example-Food.obj


More information about the Squeak-dev mailing list