readBinary

readBinary(length: Integer): Binary;

The readBinary method of the File class returns the number of bytes specified in the length parameter. An empty binary is returned if the end of file has been reached.

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

This method is valid only for files that are opened with a kind property setting of File.Kind_Binary. An exception is raised if the readBinary method is attempted on a file opened as a text file.

The following example shows the use of the readBinary method.

vars
    bin  : Binary;
    file : File;
begin
    create file;
    file.kind := File.Kind_Binary;
    file.openInput('d:\bmps\lab3.bmp');
    bin := file.readBinary(file.fileLength);
    write bin;
    return;
epilog
    delete file;
end;

The maximum size of data that can be read by the readBinary method when the value of the FileNode class usePresentationFileSystem property is set to true is 2G bytes.

If this limit is exceeded, exception 5047 (Invalid record size) is raised.