aws s3 java sdk download pdf getting corrupted

亡梦爱人 提交于 2019-12-01 10:40:45

To be honest with you, I'm willing to bet the problem is that you write the entire buffer to the FileOutputStream. At the end of the transmission, the buffer won't be completely full/overwritten and you will end up writing some bytes to the end of the file that were left over from the last read. You need to modify this code to only write the number of bytes that are actually read from the input stream, rather than the entire buffer.

Instead of

fout.write(b);

Try

fout.write(b, 0, bytesRead);

This way, if you only read 100 bytes during the last read, you only write the first 100 bytes of the buffer and ignore the remaining 8092 bytes that were actually already written to the file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!