FutureBasic Logo

<<    Index    >> FutureBasic 5

read file   statement

read file [#]deviceID,address&,numBytes&

This 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.

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&

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#; read field; write file