The read method returns how many characters it read before it reached the end offile. So, I don't see how the garbage character should be a problem. In fact,your garbage character may just be an end of file character.