In the same way, you can measure something.
System.nanoTime() returns a Long , which you can use to determine how long it takes:
Long start = System.nanoTime(); // do your read Long end = System.nanoTime();
You now have the number of nanoseconds required to read X bytes. Do the math and you have the download speed.
You are most likely looking for bytes per second. Keep track of the total number of bytes read, checking to see if one second has passed. Once one second has gone, determine the speed based on how many bytes you read in that amount of time. Reset total, repeat.
source share