You should use the ´b´ flag when opening the file, since it's supposed to be in binary right? Also, you're not catching any exceptions.