Wolfram Language & System 10.0 (2014)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)


reads all the remaining expressions in a file and returns a list of them.

reads objects of the specified type from a file, until the end of the file is reached. The list of objects read is returned.

reads objects with a sequence of types, until the end of the file is reached.

reads only the first n objects of the specified types.

Details and OptionsDetails and Options

  • Possible types to read are:
  • Bytesingle byte, returned as an integer code
    Charactersingle character, returned as a onecharacter string
    Expressioncomplete Wolfram Language expression
    Numberinteger or an approximate number, given in "E" format
    Realapproximate number, given in "E" format
    Recordsequence of characters delimited by record separators
    Stringstring terminated by a newline
    Wordsequence of characters delimited by word separators
  • Objects of type Real can be given in the scientific notation format used by languages such as C and Fortran, as well as in standard Wolfram Language format. A form like or as well as can be used to represent the number . Objects read as type Real are always returned as approximate numbers. Objects read as type Number are returned as integers if they contain no explicit decimal points.
  • The following options can be given:
  • NullRecordsFalsewhether to assume a null record between repeated record separators
    NullWordsFalsewhether to assume a null word between repeated word separators
    RecordSeparators{"\r\n","\n","\r"}separators allowed between records
    RecordListsFalsecreate separate sublists for each record
    TokenWords{}words taken as delimiters
    WordSeparators{" ","t"}separators allowed between words
  • If file is not already open for reading, ReadList opens it, then closes it when it is finished. If the file is already open, ReadList does not close it at the end.
  • ReadList prints a message if any of the objects remaining in the file are not of the specified types.
  • ReadList["file",{type1,}] looks for the sequence of in order. If the end of file is reached while part way through the sequence of , EndOfFile is returned in place of the elements in the sequence that have not yet been read.
  • ReadList[stream] reads from an open input stream, as returned by OpenRead.

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Read in each line as a separate expression:

Click for copyable input

Read each line as a string:

Click for copyable input
Introduced in 1988
| Updated in 1991