In the official repository has an example of reading file. And do not forget when you write a stream in a file, set stream position in 0. Because of this, I spent a lot of time looking for a problem