Clear The Console Programmatically In Java

一个人想着一个人 提交于 2019-12-10 20:37:21

问题


I created a sample Java application. I want to clear the window options, i.e.:

  1. Register
  2. Login
  3. Clear

If the user presses 3 I need to programmatically clear all options. Something like Console.clear?

Is there any way that I can do this with Java?


回答1:


You will need to output a bunch of blank lines. Even in Windows/*nix, clear/cls doesn't truly clear the screen, it just prints enough blank lines that you cannot see the previous text.




回答2:


You mean you created a console application and want to clear the console (not necessarily the Eclipse console)?

If so then I guess you're looking for:

Runtime.getRuntime().exec("cls");

But be aware this will be system dependent.




回答3:


If you are working with the console, then these might prove useful. Using "backspace" character. Using process builder.



来源:https://stackoverflow.com/questions/11818991/clear-the-console-programmatically-in-java

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