Reading from a low level file

The FREAD (<filehandle>,<numbytes>) function reads <numbytes> characters from the file. It starts reading from the current position in the file and moves its pointer <numbytes> characters along the file time each time that you call this function. If you ask it to read more bytes than there are in the file then it will return all the bytes available and move the pointer beyond the end of the file. No error will be raised when this happens but you can call the FEOF() function to test whether you have passed the end of the file.

This example reads groups of 10 bytes from a text file and prints them out.

lnFileHandle= FOPEN("file.txt")
DO WHILE NOT FEOF(lnFileHandle)
  ?FREAD(lnFileHandle, 10)
ENDDO
FCLOSE(lnFileHandle)

The FREAD() function treats all characters in the same way. It ignores the special meaning of ASCII characters 10 and 13 (LineFeed and CarriageReturn) and counts them as individual characters. Another low level function, FGETS() will read complete lines of characters and is much more suitable for processing text files.

Access Tips

FoxPro Tips

General Tips

 

Related Items

FoxPro Functions

FoxPro has always had functions like FREAD and FWRITE to read and write files at a low level. They can handle files which defeat the STRTOFILE and FILETOSTR functions.

Read More

Functions for manipulating text in FoxPro

Foxpro commands and functions for text

Read More

Close a low level file in FoxPro

Use FCLOSE() to close a low level file in FoxPro

Read More

Create a low level file with FoxPro

Use FCREATE() to create a low level file in FoxPro

Read More

Open a low level file in FoxPro

Use FOPEN() to open a low level file in FoxPro

Read More