How can I load a File entity? I want to find out whether a physical file is managed by Drupal and if it is, then load it.

I'm having trouble with the documentation which keeps displaying "File not found" at crucial moments, but it seemed that this ought to work:

$query = \Drupal::entityQuery('file');
$query-&gt;condition('uri', $file_uri);
$entity_ids = $query-&gt;execute();
if (count($entity_ids) == 1) {
    $file = \Drupal::entityLoad($entity_ids[0]);
}


However, I get this message: PHP Fatal error:  Call to undefined method Drupal::entityLoad()
There is no such method as \Drupal::entityLoad(). Use the static method on the entity type. Assuming "File", you should use:

$file = \Drupal\file\Entity\File::load(reset($entity_ids));


Berdir pointed out in a comment that QueryInterface::execute() returns an array keyed by entity ID or revision ID so reset() is the thing to use to get the first element.