Send to Printer


ST 4U 288: Using Files in VA Smalltalk

September 26, 2012 14:07:15.354

Today's Smalltalk 4 You looks at file i/o in VA Smalltalk - starting with the basics. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

file io.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll look at file handling in VA Smalltalk. The simplest way to get started is with FileStream - which doesn't look like it exists. That's because it's an alias for CfsFileStream:


Working with files in VA Smalltalk is fairly straightforward. You send messages to the abstract superclass (CfsFileStream), and, depending on the API, you get back the concrete subclass. You then work with that using standard stream protocol:

"Open a file read only"
stream := FileStream open: 'abt.ini' oflag: ORDONLY.
text := stream upToEnd.
stream close.

"open a file, simpler API
stream := FileStream read: 'abt.ini'.
text := stream upToEnd.
stream close.

"open for writing"
stream := FileStream write: 'test.txt'.
stream nextPutAll: 'This is a test'; cr.
stream close.

Go ahead and try those out (possibly changing the names depending on what files exist in for working directory).

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

[st4u288-iPhone.m4v ( Size: 3178135 )]

posted by James Robertson

 Share Tweet This