You're using an int
as progress counter (sentBytes
), however in the line final int progress = /*...*/
you multiply the progress counter by 100, which reduces the actual number of bytes you can use by factor 100, you should get a higher possible value by changing it to:
final int progress = (int) ((((double) sentBytes) / fileSize) * 100);
Alternately, if you have much larger files (> 2 GB), you may prefer to use a long
.