Returns a specified number of characters from a file previously opened with create( ) or open( ).

Syntax

<oRef>.read(<characters expN>)

<oRef>

A reference to the File object that created or opened the file.

<characters expN>

The number of characters to return from the specified file.

Property of

File

Description

read( ) returns the number of characters you specify from the file opened by the File object. read( ) starts reading characters from the current file pointer position, leaving the file pointer at the character immediately after the last character read. Use seek( ) to move the file pointer before or after you use read( ).

If the file to be read is a text file, use gets( ) instead. gets( ) looks for end-of-line characters, and returns the contents of the line, without the end-of-line character(s).

To write to a file, use write( ).