ReadList

WMA link


ReadList["file"]

Reads all the expressions until the end of file.

ReadList["file", type]

Reads objects of a specified type until the end of file.

ReadList["file", {$type_1$, $type_2$, ...}]

Reads a sequence of specified types until the end of file.

To read all the numbers in a file and return a list of them:

(Use FilePrint[] to get the raw data for the examples above and below.)

This does the same, but groups the numbers in to a pairs:

Now let us read and put blocks of 3 numbers in its own list:

Like Read[], ReadList handles types of objects other than numbers.
We can read a list of characters in a file putting each character as an item in a list:

And now, here are the integer codes corresponding to each of the bytes in the file:

But the data can also be read by “words”:

The above uses the default value which is space of some sort., However you can set your own value:

See WordSeparators for more information.

Reading by records uses the separators found in

See RecordSeparators works analgously for records as WordSeparators does for words.

To allow both periods and newlines as record separators:

See also Reading Textual Data.

Read
Record