How To Save Files Right
- Create temporary file. Handle all possible exceptions.
- Write data to that temporary file. Handle all possible exceptions.
- Close temporary file. During that exceptions are also possible.
- If all previous steps completes successfully, rename temporary file to existing file and handle all possible exceptions.
Steps 1-3 can be combined together if there is a function available that creates file with given content.
Following those steps prevents a lot of failures like insufficient disk space or reset during file saving.
Leave a Comment
Your email address will not be published. Required fields are marked *