In primo luogo, mi piacerebbe scusarmi per aver riportato questa domanda, ma ho sentito che avrebbe potuto usare un'altra risposta.
Derek Schultz è un tipo corretto. Il carattere '\ b' sposta il cursore di stampa indietro di un carattere, permettendoti di sovrascrivere il carattere che è stato stampato lì (non cancella l'intera riga o il carattere che era lì a meno che non stampi nuove informazioni in alto). Quello che segue è un esempio di una barra di avanzamento che utilizza Java anche se non segue il tuo formato, mostra come risolvere il problema principale della sovrascrittura dei caratteri (questo è stato testato solo in Ubuntu 12.04 con Oracle 7 su una macchina a 32 bit, ma dovrebbe funzionare su tutti i sistemi Java):
public class BackSpaceCharacterTest
{
// the exception comes from the use of accessing the main thread
public static void main(String[] args) throws InterruptedException
{
/*
Notice the user of print as opposed to println:
the '\b' char cannot go over the new line char.
*/
System.out.print("Start[ ]");
System.out.flush(); // the flush method prints it to the screen
// 11 '\b' chars: 1 for the ']', the rest are for the spaces
System.out.print("\b\b\b\b\b\b\b\b\b\b\b");
System.out.flush();
Thread.sleep(500); // just to make it easy to see the changes
for(int i = 0; i < 10; i++)
{
System.out.print("."); //overwrites a space
System.out.flush();
Thread.sleep(100);
}
System.out.print("] Done\n"); //overwrites the ']' + adds chars
System.out.flush();
}
}
La sequenza di ritorno del carriage carriage '\ r' non funziona in Eclipse a causa di un [vecchio bug] (https://bugs.eclipse.org/bugs/show_bug.cgi?id=76936) riportato nel 2004 e non risolto ancora nell'ultima versione di Eclipse (4.3.2 Kepler) –
Quindi funziona solo per una linea? –
@Sortofabeginner: In una parola, sì. – NPE