generalize file reading