What is the alternative to file_unmanaged_save_data()? In a custom module, I use this code.
file_unmanaged_save_data($data, 'private://' . $path, FILE_EXISTS_REPLACE);

The documentation for that function has the following warning.

Deprecated
In drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\File\FileSystemInterface::saveData().

So I tried using \Drupal\Core\File\FileSystemInterface::saveData($data, 'private://' . $path, FileSystemInterface::EXISTS_REPLACE),
which gives the Non-static method cannot be called statically.
Adding use Drupal\Core\File\FileSystemInterface; at the beginning of the module doesn't change anything.
In the same page, I found also a link to Unmanaged file functions replaced with a service which explains that file_unmanaged_save_data($data, $destination, $replace)
has been replaced by \Drupal::service('file_system')-&gt;saveData($data, $destination, $replace). It seems to work, but I'm still wandering:
Is there another way to do it?
Drupal always documents all the methods using ::, so you need to look closer as to whether the method is static or not.
So if you look at FileSystem::saveData



Its public and not a static. Therefore using ::saveData() is incorrect, needs to be called with the arrow -&gt;saveData()
Also, as pointed out, you need to call it with a class that implements the FileSystemInterface.