read and write to file