My part of java code is below.
while (status == DOWNLOADING) {
/* Size buffer according to how much of the
file is left to download. */
byte buffer[];
if (size - downloaded > MAX_BUFFER_SIZE) {
buffer = new byte[MAX_BUFFER_SIZE];
} else {
buffer = new byte[size - downloaded];
}
// Read from server into buffer.
int read = stream.read(buffer);
if (read == -1){
System.out.println("File was downloaded");
break;
}
// Write buffer to file.
file.write(buffer, 0, read);
downloaded += read;
}
/* Change status to complete if this point was
reached because downloading has finished. */
if (status == DOWNLOADING) {
status = COMPLETE;
}
I want to show the progress of the downloading file as percentage by updating the progress line in console. Please help. Thanks.