Task

Load the entire contents of some text file as a single string variable.

If applicable, discuss: encoding selection, the possibility of memory-mapping.

Of course, in practice one should avoid reading an entire file at once
if the file is large and the task can be accomplished incrementally instead
(in which case check File IO);
this is for those cases where having the entire file is actually what is wanted.




 
Function readFile(theFile As FolderItem, txtEncode As TextEncoding = Nil) As String
  Dim fileContents As String
  Dim tis As TextInputStream
  tis = tis.Open(theFile)
  fileContents = tis.ReadAll(txtEncode)
  tis.Close
  Return fileContents
 
Exception err As NilObjectException
  MsgBox("File Not Found.")
End Function
 