Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display progress in cmd without new lines

Tags:

java

I have a java application which run on cmd. I want to show progress while running this process. In this application 50 branches processing and I want to show after processed one branch 2% completed and after another branch processed 4% completed and so on. Problem is when I used

System.out.print("PROGRESS :" + branch_Vec.get(value).toString()+" : "+ df2.format(((a / total) * 100)) +" % \r");

as a out put it goes to new line each time it calls.

I want to show progress in same line.For example:

progress : AB : 2%
like image 464
Dilshan Avatar asked Mar 02 '26 09:03

Dilshan


1 Answers

The code System.out.print("\rComplete: "+percentage); should just work.

The \r is a carriage return, and will clear the current line. As long as you don't write a newline \n you can update the text.

Note that this does not work in the console in Eclipse, if you're using that to test.

like image 127
Matthijs Bierman Avatar answered Mar 03 '26 21:03

Matthijs Bierman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!