WriteString["file","string"]
writes "string" to a file.
WriteString[channel,"string"]
writes "string" to a stream or process.
WriteString[channel,expr1,expr2,…]
converts the expri to strings, and then writes them in sequence to the specified output channel.
WriteString
WriteString["file","string"]
writes "string" to a file.
WriteString[channel,"string"]
writes "string" to a stream or process.
WriteString[channel,expr1,expr2,…]
converts the expri to strings, and then writes them in sequence to the specified output channel.
Details
- WriteString will open a file for writing, erasing all existing data, if it is not already open.
- WriteString[File["file"],…] is also supported.
- WriteString uses the OutputForm of the expri.
- WriteString does not put a newline at the end of the output it generates.
Examples
open all close allBasic Examples (2)
Write a string to a temporary file:
file = CreateFile[];WriteString[file, "hello world"]FilePrint[file]Close[file];DeleteFile[file]str = OpenWrite[]WriteString[str, "abc", "def"]Close[str]FilePrint[%]Scope (1)
Write a string to a File object:
file = File[CreateFile[]]WriteString[file, "hello world"]Close[file]FilePrint[file]DeleteFile[file]Properties & Relations (1)
WriteString does not insert line breaks after each string it writes:
file = File[CreateFile[]]WriteString[file, "this is some text"];
WriteString[file, "this is more text"];
Close[file]FilePrint[file]Use WriteLine to automatically insert a trailing newline:
WriteLine[file, "this is some text"];
WriteLine[file, "this is more text"];
Close[file]FilePrint[file]DeleteFile[file]Tech Notes
Related Guides
History
Introduced in 1988 (1.0) | Updated in 2003 (5.0) ▪ 2016 (11.0)
Text
Wolfram Research (1988), WriteString, Wolfram Language function, https://reference.wolfram.com/language/ref/WriteString.html (updated 2016).
CMS
Wolfram Language. 1988. "WriteString." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/WriteString.html.
APA
Wolfram Language. (1988). WriteString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WriteString.html
BibTeX
@misc{reference.wolfram_2026_writestring, author="Wolfram Research", title="{WriteString}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/WriteString.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_writestring, organization={Wolfram Research}, title={WriteString}, year={2016}, url={https://reference.wolfram.com/language/ref/WriteString.html}, note=[Accessed: 15-June-2026]}