Is there a way to remove a character typed by console with System.out
or System.err
?
For example if I have a process that loads for a while, simulate an animation with the 3 ellipses ...
. Something similar to this demo on fiddle .
int puntos = 0;
final String PUNTO = ".";
System.out.print("Conectando, espera");
while (condicionQueSeCumplaAlAcabarElProceso) {
if (puntos < 3) { // comprobar cuantos puntos hay
System.out.print(PUNTO); // poner un punto
puntos ++; // indicarlo
try {
Thread.sleep(1000); // esperar 1 segundo
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
} else {
// aqui hay que borrar los 3 puntos ¿como se hace?
puntos = 0; // resetear
}
}
What you are looking for is the character
\b
that is theretroceso
orbackspace
.Using it to delete the three dots
...
as your example, it would be:An example of how to use it with numbers to represent percentage would be:
Important: The console must support the character
\b
. Some consoles (such as IDE consoles) do not support it by default.This is an example of what you want, based on what our friend Gepser shares, it is important to use
\b
for the removal of the ".
" character:Print the points one by one and then delete them to start the sequence, demo attached here
exit: