Read and write memories from/to a file