Reverse line feed in Windows / Java

折月煮酒 提交于 2019-12-23 12:33:23

问题


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

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/6756082/reverse-line-feed-in-windows-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!