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());
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter