Go to: Synopsis. Return value. Related. MEL examples.

Synopsis

fread int int|float|string|vector

fread is NOT undoable, NOT queryable, and NOT editable.

Reads the next set of bytes as binary data interpreting their type by the dummy argument. An integer dummy argument, for instance, tells fread that it should read and return an integer value. Strings are read up to the first occurrence of a NULL character or until EOF. There is a read limit of 1024 bytes on strings. If a string being read is longer than 1024 bytes, then only the first 1024 bytes will be returned. The type returned by the fread command corresponds to the type of the second argument.

Return value

intWhen second argument is anint
floatWhen second argument is a float
stringWhen second argument is a string
vectorWhen second argument is a vector

Related

fclose, feof, fflush, fgetline, fgetword, fopen, fprint, frewind, fwrite, pclose, popen

MEL examples

// Make a sample file to use as a test example
//
$exampleFileName = ( `internalVar -userTmpDir` + "example.tmp" );
$fileId=`fopen $exampleFileName "w"`;
fwrite $fileId "Hello there\n";
fclose $fileId;
// Now, open the file and read the data
//
$fileId=`fopen $exampleFileName "r"`;
string $s;
$s=`fread $fileId $s`;
print( $s + "\n" );
fclose $fileId;