How to show percentage progress of a downloading file in java console(without UI)?

aomokaoy

New Member
My part of java code is below.\[code\]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; }\[/code\]I want to show the progress of the downloading file as percentage by updating the progress line in console. Please help.Thanks.
 
Top