OpenRead

OpenRead["file"]

opens a file to read data from, and returns an InputStream object.

Details and Options

  • 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 "Files and Streams".
  • 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 Wolfram System session.
  • With the option BinaryFormat->True, the stream is opened in binary format, so that no textual interpretation of newlines or other data is done.
  • With the Method option, the stream is opened using the given input stream method. This overrides the default way that OpenRead resolves file names.
  • OpenRead[File["file"]] is also supported.

Examples

open allclose all

Basic Examples  (1)

Open a file:

Read the file:

Close the stream:

Scope  (1)

Open the file specified by the File object:

Wolfram Research (1988), OpenRead, Wolfram Language function, https://reference.wolfram.com/language/ref/OpenRead.html (updated 2016).

Text

Wolfram Research (1988), OpenRead, Wolfram Language function, https://reference.wolfram.com/language/ref/OpenRead.html (updated 2016).

CMS

Wolfram Language. 1988. "OpenRead." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/OpenRead.html.

APA

Wolfram Language. (1988). OpenRead. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OpenRead.html

BibTeX

@misc{reference.wolfram_2023_openread, author="Wolfram Research", title="{OpenRead}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/OpenRead.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_openread, organization={Wolfram Research}, title={OpenRead}, year={2016}, url={https://reference.wolfram.com/language/ref/OpenRead.html}, note=[Accessed: 19-March-2024 ]}