read and write object to or from file