This article was written to explain what is the difference between File.WriteLine and File.AppendContents.  This question was originally asked in a forum thread File.AppendContents.  And this article also shows a sample for File.ReadContents and File.WriteContents.


Difference between WriteLine and AppendContents

File.WriteLine insets a line. While File.AppendContents appends a line at the end of file. The details can be confirmed with following sample code.

Sample Code

' Sample Code for File.AppendContents, ReadContents, WriteContents
 
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
fileName = File.GetTemporaryFilePath()
File.DeleteFile(fileName)
' File.WriteContents writes contentes without CR LF
File.WriteContents(fileName, "Write line 1" + CRLF)
For i = 2 To 10
  ' File.AppendContents appends contentes with trailing CR LF
  File.AppendContents(fileName,"Append line " + i)
EndFor
File.WriteLine(fileName, 3, "Inset line 3")
File.WriteLine(fileName, 5, "Inset line 5")
File.WriteLine(fileName, 6, "Inset line 6")
TextWindow.Title = fileName
' File.ReadContents reads whole file contents
TextWindow.WriteLine(File.ReadContents(fileName))


See Also