file read/write stream implementation and example