-3

I wrote a program to send the mails one by one. I would like to print how many mails it sent . But I like to print in single places instead of 1 2 3.... or in new line. I would like to print like if it sent 1 it need to print 1 after sent 2nd then it have to erase 1 and have to print 2 in same place.

Can you help me please.

Ian Zhang
  • 11
  • 8
Kumar
  • 33
  • 1
  • 9

1 Answers1

2

To clear the screen just type:

System.out.print('\u000C');

then print updated value.

for every call first it will clear the screen and then it will print the required value.

You can also try ANSI Escape Codes:

If your terminal support them, try something like this:

System.out.print("\033[2J\033[1;1H");

You can include \0333[1;1H to be sure if \0333[2J does not move the cursor in the upper left corner.

More specifically:

•033 is the octal of ESC
•2J is for clearing the entire console/terminal screen
•1;1H moves the cursor to row 1 and column 1
Piyush Mittal
  • 1,860
  • 1
  • 21
  • 39
  • Please explain the meaning of parameter that you used, instead of plain code.. In addition, I tried ur code like this , but it gives output of `01234` printed along with some special characters in Eclipse console. `for (int i = 0; i < 5; i++) { System.out.print('\u000C'); System.out.print(i); }` – spiderman Aug 09 '15 at 03:29
  • its an ANSI escape code. are you using windows os? – Piyush Mittal Aug 09 '15 at 03:33
  • yes, please update in ur answer to be more understanding.. – spiderman Aug 09 '15 at 03:34