private void writeFile(String path, byte[] bytes) throws StorageException {
String completePath = storage + path;
File destination = new File(completePath);
makeDirectories(destination);
try (RandomAccessFile fileOnDisk = new RandomAccessFile(completePath, "rw"); //random signifie qu'on peut écrire où on veut dans le fichier
FileChannel channel = fileOnDisk.getChannel()) {
channel.lock();
channel.truncate(0); //force une réécriture totale du fichier
fileOnDisk.write(bytes);
} catch (IOException e) {
throw new StorageException(ERROR_SAVING_FILE, e.getMessage());
}
}