Java: How to print out working dots in terminal

tsume

The Pervy Sage
Joined
Apr 19, 2010
Messages
21,130
Reaction score
373
Location
In the vasts of the internet
I've this project I'm doing where I'm going to have go through about 500GB of data and doing comparisons to another database which is about 1TB database where a single file is about 70KB. So yeah, this is going to take time. Though I've been printing out statements to make sure everything which I need to working is being done correctly, I'm now about to clean that up so only import errors are reported, which is rare.

So I thought it would best to print out something which shows that the program is busy. I was thinking of a 3 dots print out which would be something like this:
.
..
...
On the same line, each dot gets printed out every second or so gets cleared out then starts printing the dots again. Any idea of how to approach? This is what I've gotten to:

Code:
while(true){
            System.out.print(".");
            Thread.sleep(1000);
            System.out.print(".");
            Thread.sleep(1000);
            System.out.print(".");
            Thread.sleep(1000);
            System.out.print("\r");

        }
Which does do what I want it to do as the "\r" does not clear line (just wanted to show where I'm going at). So I need something to clear the line and not the whole terminal screen.

Thanks
 
Last edited:
why not just make your last line:
Code:
System.out.print("\r                                                            \r");
 
Last edited:
Prints out this "... ... ... ... ...". Someone ran a code for about + 24 hours and it still had not gone through the whole database. So having a terminal filled with "... ... ... ... ...", rather than one line with just "..." is going to be messy, especially if an error where to be catched.
 
Dont see why it would do what you suggest.
if the last line does a \r to put the cursor at the start of the line then prints a whole bunch of spaces over the dots on theat line and finally does another \r to put the cursor art the start you should see three dots appear one by one and then vanish only to start again.
 
I know in c++ you can do a system calls within your program, you can call a "clr" or "clear" (depending on if youre using windoze or linux). im sure there is a java equivalent

this clears your entire terminal, i dont know if this is what you want.
 
I know in c++ you can do a system calls within your program, you can call a "clr" or "clear" (depending on if youre using windoze or linux). im sure there is a java equivalent

this clears your entire terminal, i dont know if this is what you want.
Java has something similar but it also clears the whole terminal, not what I'm looking

If you can use a 3rd party library, try jansi (came up in a Google search) and then some commands from here

Thanks. Will take a look at it later.

why not print out a percentage / number of records processed instead?
That's fine but again I would need the line to be cleared to print out the percentage without having the terminal filled up percentages.
 
I use to do this under DOS a lot and the best was to use a string. Populate the string with the dots and white space.

My favourite was still to do the spinning star where you only show one char at a time: |\-/+* I looks really cool
 
Top
Sign up to the MyBroadband newsletter
X