peek

peek(length: Integer): String;

The peek method of the File class returns a string containing the number of characters specified in the length parameter, starting from the current position. The current file offset is unchanged.

The peek method automatically opens the file if it is not already open.

You can use the peek method only with files opened as text files.

An exception is raised if the value specified in the length parameter is not a positive number; that is, greater than zero (0).

If you specify a number of characters greater than the length of the file, only the characters up to the end of the file are returned. An empty string is returned when the current position is the end of file.

The code fragment in the following example shows the use of the peek method.

str := file.peek(10);
if str[1:3] = "***" then
    file.readLine;
    return true;
endif;