This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Input and Output / File Input  /
OpenRead

  • OpenRead[" file "] opens a file to read data from, and returns an InputStream object.
  • OpenRead prepares to read from a file, starting at the beginning of the file.
  • On systems that support pipes, OpenRead["! command "] runs the external program specified by command, and opens a pipe to get input from it.
  • If OpenRead does not succeed in opening a particular file or pipe, it generates a message, and returns $Failed.
  • OpenRead resolves file names according to the procedure described in Section A.6.1.
  • The function ReadList automatically opens files or pipes that it needs.
  • OpenRead returns InputStream[" name ", n ], where name is the full name of a file or command, and n is a serial number that is unique across all streams opened in the current Mathematica session.
  • Setting the option DOSTextFormat->True causes all input to be treated as coming from a text-mode file on an MS-DOS or related system. This means that \n\r pairs are interpreted as single newlines, and Z is interpreted as EndOfFile.
  • See the Mathematica book: Section 2.11.7.
  • See also: Close, Read, ReadList, Streams, LinkCreate.