Answer the question
In order to leave comments, you need to log in
How in Java to remove the last character or line printed on the terminal screen?
Is there such a possibility in principle?
Answer the question
In order to leave comments, you need to log in
There is a possibility, but it has nothing to do with Java. This can be done using the so-called. Escape sequences, if they are supported by the terminal (if the terminal is running in emulation mode, for example, VT-52 or VT-100). Most of the terminals in Linux work in this mode.
You can delete the last line printed with a carriage return character (when the cursor is at position 1 of the next line after the line is displayed), for example, like this:
System.out.println("Hello world"); //Print the line
System.out.print(String.format("\033[%dA",1)); // Move cursor up by 1 line
System.out.print("\033[2K"); // Erase the line
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question