Next: , Previous: Your own stream, Up: Streams

6.10.3 Files

Streams can also operate on files. If you wanted to dump the file /etc/passwd to your terminal, you could create a stream on the file, and then stream over its contents:

        f := FileStream open: '/etc/passwd' mode: FileStream read
        f linesDo: [ :c | Transcript nextPutAll: c; nl ]
        f position: 30
        25 timesRepeat: [ Transcript nextPut: (f next) ]
        f close

and, of course, you can load Smalltalk source code into your image:

        FileStream fileIn: '/Users/myself/src/'