Check access to a file before opening them

Detect and handle file operation errors

Do not reference file handles after the file they have been associated with is closed

flush buffered file input