({{, (RefLink[WriteLine, paclet:ref/WriteLine])["file","string"]
writes "string" to a file, followed by a newline.}, {, (RefLink[WriteLine, paclet:ref/WriteLine])[stream,"string"] 
writes "string", followed by a newline, to the specified output stream.}, {, (RefLink[WriteLine, paclet:ref/WriteLine])[proc,"string"]
writes "string" to an external process proc.}})

OpenersNotesSection(Spacer1)Details

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

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

OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Write a string to a temporary file:

file=CreateFile[];

WriteLine[file,"hello world"]

Print the file:

FilePrint[file]

Delete the temporary file:

DeleteFile[file]

Start the system shell process:

process=StartProcess[$SystemShell]

Write a command into the shell process:

WriteLine[process,"echo example line"];

Read one line from the shell output:

ReadLine[process]

OpenersExampleSection1(Spacer1)Scope  (2)

Open a stream:

str=OpenWrite[];

Write a line into the file:

WriteLine[str,"1234"];

Close the stream:

Close[str];

Print the contents that were written:

FilePrint[First[str]]

Create a temporary file:

file=File[CreateFile[]]

Write a line of text:

WriteLine[file,"this is some text"]

WriteLine[file,"this is more text"]

Close[file]

Both lines were written:

FilePrint[file]

Delete the temporary file:

DeleteFile[file]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

(RefLink[WriteLine, paclet:ref/WriteLine]) inserts line breaks after each string it writes:

file=File[CreateFile[]]

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

FilePrint[file]

(RefLink[WriteString, paclet:ref/WriteString]) does not insert line breaks automatically:

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

FilePrint[file]

Delete the temporary file:

DeleteFile[file]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ReadLine, paclet:ref/ReadLine])  ▪  (RefLink[WriteString, paclet:ref/WriteString])  ▪  (RefLink[Write, paclet:ref/Write])  ▪  (RefLink[Export, paclet:ref/Export])  ▪  (RefLink[BinaryWrite, paclet:ref/BinaryWrite])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Files, paclet:guide/Files])}, {▪(RefLinkPlain[Direct Control of External Processes, paclet:guide/DirectControlOfExternalProcesses])}, {▪(RefLinkPlain[Low-Level File Operations, paclet:guide/LowLevelFileOperations])}})}})