Readable.Read

From Xojo Documentation

Method

Readable.Read(Count as Integer[,Enc as TextEncoding]) As String

Supported for all project types and targets.

Reads Count bytes from the input stream and returns a String.

Notes

If provided, the optional parameter Enc specifies the text encoding to be defined for the String to be read.

If Count is higher than the amount of bytes currently available in the stream, all available bytes will be returned. Therefore, make sure to always consider the case that you get less than you requested. To see if you received all requested bytes, check the returned string’s String.Bytes property (avoid using Length as it may give a different number if the encoding is not nil).

If not enough memory is available, you get back an empty string.

Example

This example reads the first 1000 bytes from a BinaryStream.

Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("text/plain")
If readFile <> Nil Then
Var ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
ReadStream.LittleEndian = True
TextArea1.Value = ReadStream.Read(1000, Encodings.UTF8)
End If