- You communicate with files via input streams and output streams.
- If you want to open an input file for reading,
then instantiate the following pattern:
File pathName: 'file specification'
- If you want to open an output file for writing,
then instantiate the following pattern:
File newFile: 'file specification'
- If you are finished with an input or output stream,
then you should close it by instantiating the
following pattern:
stream close
- If you want to read a whitespace-delimited
String
instance from a stream, then
instantiate the following pattern:
stream nextWord
- If you want to read an
Integer
instance from a
stream, then instantiate the following pattern:
stream nextWord asInteger
- If you want to read from a stream as long as it has wordlike strings to be
read, then instantiate the following pattern:
[(variable := stream nextWord) notNil]
whileTrue: [appropriate statements].
- If you want to read a single character from a stream, then send the
next
message to the stream.
- If you want to write a string to a stream, then instantiate the
following pattern:
stream nextPutAll: 'the characters in the string'
- If you want to denote a character, then prefix the character with
$
, so that Smalltalk will not interpret the character as a
variable name.
- If you want to write a character to a stream, then instantiate the
following pattern:
stream nextPut: the character