我的java代码部分如下。
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;
}
我想通过更新控制台中的进度行以百分比形式显示下载文件的进度。请帮忙。谢谢。