Input and Output

Rexx supports a stream I/O model. Using streams, your program reads data from various devices (such as hard disks, CD-ROMs, and keyboards) as a continuous stream of characters. Your program also writes data as a continuous stream of characters.

In the stream model, a text file is represented as a stream of characters with special line-end characters marking the end of each line of text in the stream.

We use the expression "line-end characters" because they are platform dependent, and may be a single character (UNIX / Linux and Mac OS X use a single line feed character ( '0D'x, 13 decimal), classic Mac used a single carriage return character ('0A'x, 10 decimal) or a character combination (Windows / DOS uses a carriage-return and line-feed character pair ('0D 0A'x)). Henceforth, when we use the expression "line-end characters", we mean whatever character sequence constitutes the line termination sequence on whichever platform you are working with Rexx on.

A binary file is a stream of characters without an inherent line structure. A Rexx stream object allows you read from a data stream using either the text-file line methods or using a continuous data stream method.

The Rexx Stream class is the mechanism for accessing I/O streams. To input or output data, you first create an instance of the Stream class that represents the device or file you want to use. For example, the following clause creates a stream object for the file out.dat:

/* Create a stream object for out.dat */
file=.stream~new("out.dat")

Then you use the appropriate stream methods to read and/or write the data. out.dat is a text file, so you would normally use the LINES(), LINEIN, and LINEOUT() methods that read or write data as delimited lines. If the stream represents a binary file (such as a wav, gif, tif or exe), you would use the CHARS, CHARIN, and CHAROUT methods that read and write data as characters.

The Stream class includes additional methods for opening and closing streams, flushing buffers, seeking to specific file locations, retrieving stream status, and other I/O operations.