Source: http://umich.edu/~eecs381/handouts/filestreams.pdf