Java display of command line changes

I wrote a Java program that loads data from a file, and I show the download progress on the command line, printing a message on the screen after every n entries, which looks like this:

$> 100 records processed.

$> 200 records processed.

$> 300 records processed.

$> 400 records processed.

$> 500 records processed.

...

However, I would like to just print ONE line and only update the number, i.e. so that the output always looks like this:

$> processed <n> records.

How to do it in Java and is it possible?

+5
source share
2 answers

, backspace , :

int[] step = {100,200,300,400,500};
System.out.print("$> processed < ");
for (int i : step) {
   System.out.print(i + " > records.\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
   Thread.sleep(500);
}

Windows, , , Eclipse.

, "\ b", .

@Reza, "\ r" :

int[] step = {100,200,300,400,500};
for (int i : step) {
   System.out.print("$> processed < " + i + " > records.\r");
   Thread.sleep(500);
}

- Eclipse ( , ), . , , .

+5

, . :

?

+1

All Articles