read and write a file