Reverse line feed in Windows / Java

2019-06-28 04:07发布

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

2条回答
劫难
2楼-- · 2019-06-28 04:09

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-06-28 04:24

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

查看更多
登录 后发表回答