FutureBasic Logo

<<    Index    >> FutureBasic

read file   function / statement



Syntax 1
cfString = read file fileID [, @err ]

Syntax 2
read file [#]deviceID, address, numBytes

Description

Syntax 1:
With this syntax, the read file function returns a CFString containing the entire contents of the open file.

Important note: read file's syntax 1 must be matched with the correct open method for use with CFStrings. See syntax 1 for open ).

Example

ErrorRef err = NULL
CFStringRef string = read file 1, @err
if ( string )
print string
else
print err
end if
Syntax 2:
With this syntax, the read file statement reads numBytes bytes from the open file or serial port specified by deviceID (starting at the current "file mark" position), and copies them into memory starting at the address specified by address. This is the fastest way to read large amounts of data from a file; it's also well suited for reading data whose format you may not know in advance.

Important note: read file's syntax 2 must be matched with the correct open method for use with a pointer to a buffer. See syntax 2 for open ).

Example

This program fragment quickly loads an array with the data read from a file. It's assumed that the binary image of the array was previously saved to the file using a statement like write file (see the example accompanying the write file statement).

_maxSubscript = 200
dim myArray(_maxSubscript)
arrayBytes = (_maxSubscript+1) * sizeof(int)
read file #1, @myArray(0), arrayBytes

Note
If read file attempts to read past the end of the file (because numBytes> was too large), FutureBasic generates an error.

See also
open; read#; write file