OpenWrite
✖
OpenWrite
Details and Options


- OpenWrite deletes any existing contents in a file, and prepares to write output starting at the beginning of the file.
- The following options can be given:
-
BinaryFormat False whether to use binary format for the file CharacterEncoding Automatic what raw character encoding to use FormatType InputForm default format for printing expressions NumberMarks $NumberMarks when to use ` marks in approximate numbers PageWidth 78 number of character widths per line TotalWidth Infinity maximum number of character widths for a single expression Method Automatic stream method to use - On computer systems that support pipes, OpenWrite["!command"] runs the external program specified by command, and opens a pipe to send input to it.
- If OpenWrite does not succeed in opening a particular file or pipe, it generates a message and returns $Failed.
- OpenWrite resolves file names according to the procedure described in "Files and Streams".
- OpenWrite returns OutputStream["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.
- SetOptions can be used to change the properties of an output stream after it is already open.
- Functions like Put and Write automatically open the files or pipes they need, if they are not already open.
- With the default setting BinaryFormat->False, the setting for CharacterEncoding is taken to be "ASCII".
- OpenWrite[] always creates a new file that does not already exist, in the directory given by $TemporaryDirectory.
- With the Method option, the stream is opened using the given input stream method. This overrides the default way that OpenWrite resolves file names.
- OpenWrite[File["file"]] is also supported.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Create and open a new stream for writing:
In[1]:=1

✖
https://wolfram.com/xid/0tz6swr2-p00zaz
In[2]:=2

✖
https://wolfram.com/xid/0tz6swr2-bdjg8c
Out[2]=2

Write an expression to the stream:
In[3]:=3

✖
https://wolfram.com/xid/0tz6swr2-he57ks
In[4]:=4

✖
https://wolfram.com/xid/0tz6swr2-ej1sgx
Out[4]=4

In[5]:=5

✖
https://wolfram.com/xid/0tz6swr2-jjbo1t
Scope (1)Survey of the scope of standard use cases
Write an expression to the file specified by the File object:
In[1]:=1

✖
https://wolfram.com/xid/0tz6swr2-i7c56z
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0tz6swr2-bzvdwh
In[3]:=3

✖
https://wolfram.com/xid/0tz6swr2-bxdxvt
In[4]:=4

✖
https://wolfram.com/xid/0tz6swr2-cdsuza
In[5]:=5

✖
https://wolfram.com/xid/0tz6swr2-l1d0d
Wolfram Research (1988), OpenWrite, Wolfram Language function, https://reference.wolfram.com/language/ref/OpenWrite.html (updated 2016).
✖
Wolfram Research (1988), OpenWrite, Wolfram Language function, https://reference.wolfram.com/language/ref/OpenWrite.html (updated 2016).
Text
Wolfram Research (1988), OpenWrite, Wolfram Language function, https://reference.wolfram.com/language/ref/OpenWrite.html (updated 2016).
✖
Wolfram Research (1988), OpenWrite, Wolfram Language function, https://reference.wolfram.com/language/ref/OpenWrite.html (updated 2016).
CMS
Wolfram Language. 1988. "OpenWrite." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/OpenWrite.html.
✖
Wolfram Language. 1988. "OpenWrite." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/OpenWrite.html.
APA
Wolfram Language. (1988). OpenWrite. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OpenWrite.html
✖
Wolfram Language. (1988). OpenWrite. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OpenWrite.html
BibTeX
✖
@misc{reference.wolfram_2025_openwrite, author="Wolfram Research", title="{OpenWrite}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/OpenWrite.html}", note=[Accessed: 28-February-2025
]}
BibLaTeX
✖
@online{reference.wolfram_2025_openwrite, organization={Wolfram Research}, title={OpenWrite}, year={2016}, url={https://reference.wolfram.com/language/ref/OpenWrite.html}, note=[Accessed: 28-February-2025
]}