Below is a code fragment. Basically, $fread returns a value that you can test for errors. If the return_value is not 1 then you have gone past the end of the file, ie an EOF error.
---- Steve
///////////////////////////////////////////////////////////////////////////////////////////
integer return_value, file ;
reg [7:0] mem, tmp_byte, tmp_nibble;
reg error;
file = $fopen("code.vec", "r");
$ferror(file, error);
if (error != 0)
$display("\nFile Open Failed with Error Code = %x", error);
return_value = $fread( mem, file);
if (return_value !=1)
error = 1;