Is there a way to write several lines to the system console in Windows, then delete or modify them, using Java? I can write over the same line more than once using the \r
carriage return character. The Cygwin command less
(a text viewer) manages it (although it's not Java), so I suspect it's possible.
I've tried \u008D
which is (according to a page I googled) the reverse line feed character, but it doesn't seem to work.
System.out.println("1");
System.out.println("2");
System.out.print("\u008D");
System.out.println("3");
outputs
1
2
?3
whereas I'd hoped to see
1
3
The JLine library can give more advanced console control when nothing else works. Be aware that it uses native code.
The killLine() method may be what you are after if you end up using JLine.
Try
System.out.print("\b");
It doesn't work in eclipse (bug - source ) but should work otherwise.