({{, (RefLink[WriteString, paclet:ref/WriteString])["file","string"]
writes "string" to a file.}, {, (RefLink[WriteString, paclet:ref/WriteString])[channel,"string"]
writes "string" to a stream or process.}, {, (RefLink[WriteString, paclet:ref/WriteString])[channel,(Subscript[expr, 1]),(Subscript[expr, 2]),…]
converts the (Subscript[expr, i]) to strings, and then writes them in sequence to the specified output channel. }})

OpenersNotesSection(Spacer1)Details

(RefLink[WriteString, paclet:ref/WriteString]) will open a file for writing, erasing all existing data, if it is not already open.

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

(RefLink[WriteString, paclet:ref/WriteString]) uses the (RefLink[OutputForm, paclet:ref/OutputForm]) of the (Subscript[expr, i]).

(RefLink[WriteString, paclet:ref/WriteString]) does not put a newline at the end of the output it generates.

OpenersPrimaryExamplesSection(Spacer1)Examples  (4)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Write a string to a temporary file:

file=CreateFile[];

WriteString[file,"hello world"]

Print the file:

FilePrint[file]

Delete the temporary file:

DeleteFile[file]

Open a stream:

str= OpenWrite[]

Write to the stream:

WriteString[str,"abc","def"]

Close the stream:

Close[str]

Print the file:

FilePrint[%]

OpenersExampleSection1(Spacer1)Scope  (1)

Write a string to a (RefLink[File, paclet:ref/File]) object:

file=File[CreateTemporary[]]

WriteString[file,"hello world"]

Close[file]

Print the file:

FilePrint[file]

Delete the file:

DeleteFile[file]

OpenersExampleSection2(Spacer1)Properties & Relations  (1)

(RefLink[WriteString, paclet:ref/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 (RefLink[WriteLine, paclet:ref/WriteLine]) to automatically insert a trailing newline:

WriteLine[file,"this is some text"];
WriteLine[file,"this is more text"];
Close[file]

FilePrint[file]

Delete the temporary file:

DeleteFile[file]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ReadString, paclet:ref/ReadString])  ▪  (RefLink[WriteLine, paclet:ref/WriteLine])  ▪  (RefLink[Write, paclet:ref/Write])  ▪  (RefLink[ExportString, paclet:ref/ExportString])  ▪  (RefLink[BinaryWrite, paclet:ref/BinaryWrite])  ▪  (RefLink[DeviceRead, paclet:ref/DeviceRead])  ▪  (RefLink[ProcessObject, paclet:ref/ProcessObject])  ▪  (RefLink[OutputStream, paclet:ref/OutputStream])  ▪  (RefLink[LinkWrite, paclet:ref/LinkWrite])  ▪  (RefLink[TextString, paclet:ref/TextString])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Streams and Low-Level Input and Output, paclet:tutorial/StreamsAndLowLevelInputAndOutput])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Files, paclet:guide/Files])}, {▪(RefLinkPlain[Network Programming, paclet:guide/NetworkProgramming])}, {▪(RefLinkPlain[Low-Level File Operations, paclet:guide/LowLevelFileOperations])}})}})