Jak pokazać procentowy postęp pobierania pliku w konsoli java (bez interfejsu użytkownika)?

Moja część kodu java jest poniżej.

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;

        }

Chcę pokazać postęp pobierania pliku w procentach, aktualizując linię postępu w konsoli. Proszę pomóż. Dzięki.

questionAnswers(4)

yourAnswerToTheQuestion