Hi all,

I have a program which bulk-downloads files from a remote server. The program runs in console (I am not using SWING or AWT).

I would like to show progres (e.g. progress bar) while the files are being downloaded. Can someone point me to right direction... which classes to look into?

Appreciate your inputs.


Thanks.

About the only thing that comes to mind is to use System.out.print() (not println) to print the file name and then append periods after it until it's done, and then println "complete" and move along to the next file.
There isn't really a mechanism to overwrite a line of output to the console, so unless you want to print numbers in sequence to represent percent complete, or write them on separate lines, you're limited in what you can display for it.

You might be able to send backspace characters to clear a previous number and then overwrite it, but I have played with it really and it would probably not be platform independent.

About the only thing that comes to mind is to use System.out.print() (not println) to print the file name and then append periods after it until it's done, and then println "complete" and move along to the next file.
There isn't really a mechanism to overwrite a line of output to the console, so unless you want to print numbers in sequence to represent percent complete, or write them on separate lines, you're limited in what you can display for it.

You might be able to send backspace characters to clear a previous number and then overwrite it, but I have played with it really and it would probably not be platform independent.

Thanks for replay,

I am able to show a spinning symbole (which is good enough). However, I can't show it while the files are being downloaded. Here's the example:

public final class TestProgress{
    private static final char progress[] = { '-', '\\', '|', '/' };
    private static int progressCycle = 0;
    public static void main( String[] args ){
    // Can I do, like: startDownload(); and set some condition in for () loop
    // to break out  when download completed??? It doesn't seem to work
        for ( int i = 0; i < 20; i++ ){
            try{
                Thread.sleep( 250 );
            }catch ( InterruptedException e ){
            }
            System.out.print( progress[ progressCycle ] + "\b" );
            progressCycle = ( progressCycle + 1 ) & 3;
        }
    }
}

So, this piece of code, only displays the spinner. How can I use this to show the spinner while the files are being downloaded?? Please advise...


Thanks.

You will have to utilize a separate thread for the progress update. The easiest would probably be a Timer. See How to Use Timers for more information on this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.