|
|
3.3 Disk file-IO primitive messages
Four classes (FileDescriptor , FileStream , File ,
Directory ) allow you to create files and access the file system
in a fully object-oriented way.
FileDescriptor and FileStream are much more powerful than the
corresponding C language facilities (the difference between the two is that,
like the C `stdio' library, FileStream does buffering). For one
thing, they allow you to write raw binary data in a portable endian-neutral
format. But, more importantly, these classes transparently implement
asynchronous I/O: an input/output operation blocks the Smalltalk Process
that is doing it, but not the others, which makes them very useful in the
context of network programming. For more information on these classes,
look in the class reference.
In addition, the three files, stdin , stdout , and stderr
are declared as global instances of FileStream that are bound to the
proper values as passed to the C virtual machine. They can be accessed as
either stdout and FileStream stdout ---the former is easier to
type, but the latter can be clearer.
Finally, Object defines four other methods: print and
printNl , store and storeNl . These do a printOn: or
storeOn: to the "Transcript" object; this object, which is the sole
instance of class TextCollector , normally delegates write
operations to stdout . If you load the Blox GUI, instead,
the Transcript Window will be attached to the Transcript object (see section 3.7.1 Blox).
The fileIn: message sent to the FileStream class, with a file
name as a string argument, will cause that file to be loaded into
Smalltalk.
For example,
| FileStream fileIn: 'foo.st' !
|
will cause `foo.st' to be loaded into GNU Smalltalk.
|