FREAD( ) (Función)

Devuelve el número de bytes especificado desde un archivo abierto con una función de bajo nivel.

FREAD(nFileHandle, nBytes)

Valores devueltos

Character

Parámetros

  • nFileHandle
    Especifica el número de controlador de archivo para el archivo desde el cual FREAD( ) devuelve datos. Puede obtener nFileHandle a partir del valor devuelto por instrucciones FOPEN( ) o FCREATE( ) correctamente ejecutadas.
  • nBytes
    Especifica el número de bytes que devuelve FREAD( ). FREAD( ) devuelve datos a partir de la posición actual del puntero de archivo y continúa hasta que devuelve nBytes bytes o hasta que encuentra el final del archivo, lo que ocurra primero.

Ejemplo

El ejemplo siguiente usa FREAD( ) para mostrar el contenido de un archivo. Si el archivo está vacío, se muestra un mensaje.

* TEST.TXT must exist -- you can create this file
* using Notepad.

Local gnFileHandle,nSize,cString
gnFileHandle = FOPEN("test.txt")
* Seek to end of file to determine the number of bytes in the file
nSize =  FSEEK(gnFileHandle, 0, 2)     && Move pointer to EOF
IF nSize <= 0
 * If the file is empty, display an error message
 WAIT WINDOW "This file is empty!" NOWAIT
ELSE
 * If file is not empty, the program stores its contents
 * in memory, then displays the text on the main Visual FoxPro window
 = FSEEK(gnFileHandle, 0, 0)      && Move pointer to BOF
 cString = FREAD(gnFileHandle, nSize)
 ? cString
ENDIF
= FCLOSE(gnFileHandle)         && Close the file

Vea también

FCHSIZE( ) | FCLOSE( ) | FCREATE( ) | FEOF( ) | FFLUSH( ) | FGETS( ) | FILETOSTR( ) | FOPEN( ) | FPUTS( ) | FSEEK( ) | FWRITE( )