({{, (RefLink[OpenRead, paclet:ref/OpenRead])["file"]
opens a file to read data from, and returns an (RefLink[InputStream, paclet:ref/InputStream]) object.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[OpenRead, paclet:ref/OpenRead]) prepares to read from a file, starting at the beginning of the file.

On systems that support pipes, (RefLink[OpenRead, paclet:ref/OpenRead])["!command"] runs the external program specified by command, and opens a pipe to get input from it.

If (RefLink[OpenRead, paclet:ref/OpenRead]) does not succeed in opening a particular file or pipe, it generates a message and returns (RefLink[$Failed, paclet:ref/$Failed]).

(RefLink[OpenRead, paclet:ref/OpenRead]) resolves file names according to the procedure described in "Files and Streams".

The function (RefLink[ReadList, paclet:ref/ReadList]) automatically opens files or pipes that it needs.

(RefLink[OpenRead, paclet:ref/OpenRead]) returns (RefLink[InputStream, paclet:ref/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 (RefLink[BinaryFormat, paclet:ref/BinaryFormat])->(RefLink[True, paclet:ref/True]), the stream is opened in binary format, so that no textual interpretation of newlines or other data is done.

With the (RefLink[Method, paclet:ref/Method]) option, the stream is opened using the given input stream method. This overrides the default way that (RefLink[OpenRead, paclet:ref/OpenRead]) resolves file names.

(RefLink[OpenRead, paclet:ref/OpenRead])[(RefLink[File, paclet:ref/File])["file"]] is also supported.

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Open a file:

str=OpenRead["ExampleData/USConstitution.txt"]

Read the file:

Read[str, Word]

Read[str, Word]

Read[str, Word]

Close the stream:

Close[str]

OpenersExampleSection1(Spacer1)Scope  (1)

Open the file specified by the (RefLink[File, paclet:ref/File]) object:

str=OpenRead[File["ExampleData/USConstitution.txt"]];

Read[str, Word]

Close[str];

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Close, paclet:ref/Close])  ▪  (RefLink[Read, paclet:ref/Read])  ▪  (RefLink[ReadList, paclet:ref/ReadList])  ▪  (RefLink[Streams, paclet:ref/Streams])  ▪  (RefLink[LinkCreate, paclet:ref/LinkCreate])  ▪  (RefLink[OpenWrite, paclet:ref/OpenWrite])  ▪  (RefLink[OpenAppend, paclet:ref/OpenAppend])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Reading Textual Data, paclet:tutorial/ReadingTextualData])}, {▪(RefLinkPlain[Streams and Low-Level Input and Output, paclet:tutorial/StreamsAndLowLevelInputAndOutput])}, {▪(RefLinkPlain[Stream Methods, paclet:tutorial/StreamMethods])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Files, paclet:guide/Files])}, {▪(RefLinkPlain[File Operations, paclet:guide/FileOperations])}, {▪(RefLinkPlain[Low-Level File Operations, paclet:guide/LowLevelFileOperations])}, {▪(RefLinkPlain[External Operations, paclet:guide/ExternalOperations])}, {▪(RefLinkPlain[Basic Input & Output in Programs, paclet:guide/BasicInputAndOutputInPrograms])}, {▪(RefLinkPlain[Procedural Programming, paclet:guide/ProceduralProgramming])}})}})