开发者

Reverse line feed in Windows / Java

开发者 https://www.devze.com 2023-03-21 06:50 出处:网络
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. T

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");
    Syst开发者_运维知识库em.out.println("3");

outputs

1
2
?3

whereas I'd hoped to see

1
3


Try System.out.print("\b"); It doesn't work in eclipse (bug - source ) but should work otherwise.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消