function write and read.