About File::replaceWithData()


#1

In JUCE API Document, File class:

bool File::replaceWithData (const void * dataToWrite, int numberOfBytes ) const

A nice feature of this method is that it’s safe - instead of deleting the file first and then re-writing it, it creates a new temporary file, writes the data to that, and then moves the new file to replace the existing file. This means that if the power gets pulled out or something crashes, you’re a lot less likely to end up with an empty file

you’re a lot less likely to end up with an empty file.

I can’t understand this, what does that mean?
Thanks!


#2

It should probably say “you’re less likely to end up with a corrupted file”… Just meaning that this method is a more robust way to write a lump of data to a file that it would be to delete the file and re-write it.


#3

Understand! :smiley:

Thanks Jules.