MM Manuel MM Manuel - 1 year ago 146
Android Question

Progress of dataOutputStream.readFully

I'm receiving a file using dataInputStream.readFully, so
i'd like to show the progress of the transmision.
Is it possible to know the progress of readFully method?
Thank you.

Answer Source

No - the whole point is that it's a single call to make it simpler to read.

If you want to read more gradually (e.g. to update a progress bar) you can just read a chunk at a time with[], int, int) in a loop until you've read all the data. For example:

byte[] data = new byte[bytesToRead];
int offset = 0;
int bytesRead;
while ((bytesRead =, offset, data.length - offset)) > -1) {
    offset += bytesRead;
    // Update progress indicator

This is just like the JDK 8 code for readFully, but with progress indication in the loop.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download