Reading Dictionary from File
SWallace
scottw at wdi.disney.com
Sat Dec 5 20:44:43 UTC 1998
Cameron,
For a really simple alternative, consider using the ReferenceStream mechanism. We use it all the time to transport arbitrary structures from image to image.
If you have a dictionary stored in variable X, for example, you can save it to a file named "XFile" by simply evaluating:
(ReferenceStream fileNamed: 'XFile') nextPut: X; close
To internalize the data from such a file, you just evaluate code of the form:
aReferenceStream _ ReferenceStream fileNamed: 'XFile'.
X _ aReferenceStream next.
aReferenceStream close
A typical pair of methods used in Squeak in this manner will be found in StandardScriptingSystem methods #saveFormsToFileNamed: and #readFormsFromFileNamed:, which we use to transport a standard dictionary of graphics from one build to the next.
-- Scott
At 7:26 AM -0800 12/5/98, Cameron Bowes wrote:
>Hi Folks!
>
>I've got a dictionary of timing data that I keep in a text file. I finally
>decided to work up a couple of methods to basically dump the thing out and
>read it back in.
>
>To dump it, I open a FileStream and use storeOn: to stream it out to the
>file. So I have a file with the Dictionary all neatly arranged to be read
>back in. Which I can cut and paste into a workspace with a variable
>assignment to recreate the Dictionary.
>
>I'd like to read it back in directly from the file though, and this is where
>I'm stumped (yes, I'm a relative newbie). I open the FileStream, and then
>use contentsOfEntireFile to grab the data, which passes me back a string.
>Assigning that to a variable gives me just that, a string. What I'd like to
>do is pass the thing to the variable so that the Dictionary definition gets
>recreated.
>
>I think I must be missing something really simple here! TIA for any
>suggestions!
>
>Regards,
>
>Cam Bowes
>cbowes at mnsinc.com
More information about the Squeak-dev
mailing list
|