# Command: WriteLine$

WriteLine$ (filehandle|stream, string$) Definition:

Writes a single line of text to an open file (or stream).

Parameter Description:

filehandle|stream = a valid variable set with the OpenFile, WriteFile command, or OpenTCPStream (v1.52+). The value returned is a text string. string$ = valid string value.

Command Description:

Once you've opened a disk file (or stream) for writing, use this command to right a whole line of text to the file. Each line of text is automatically terminated with an "end-of-line" mark, consisting of a Carriage Return character followed by a LineFeed character. (i.e. 0Dh, 0Ah ) This function can be used to make plain text files.
Streams can only be used in Blitz Basic v1.52 or greater.
See also:
ReadByte, ReadShort, ReadInt, ReadFloat, ReadString$, ReadLine$, WriteByte, WriteShort, WriteInt, WriteFloat, WriteShort, WriteString, WriteLine, ReadFile, WriteFile, OpenFile, CloseFile, Eof, FileType, FilePos, SeekFile

Example:

; Reading and writing a file using ReadLine$ and WriteLine functions
; Initialise some variables for the example
String1$ = "Line 1 is short"
String2$ = "Line 2 is a longer line but they can be much longer"
String3$ = "Line 3 is made up "
String4$ = "of two parts joined together."
; Open a file to write to
fileout = WriteFile("mydata.txt")
; Write the information to the file
WriteLine( fileout, String1 )
WriteLine( fileout, String2 )
WriteLine( fileout, String3 + String4)
WriteLine( fileout, "Just to show you don't have to use variables" )
; Close the file
CloseFile( fileout )
; Open the file to Read
filein = ReadFile("mydata.txt")
Read1$ = ReadLine( filein )
Read2$ = ReadLine$( filein )
Read3$ = ReadLine$( filein )
Read4$ = ReadLine$( filein )
; Close the file once reading is finished
CloseFile( fileout )
Print "Lines of text read from file - mydata.txt "
Print
Print Read1
Print Read2
Print Read3
Print Read4
WaitKey()

Index