问题
I created a sample Java application. I want to clear the window options, i.e.:
- Register
- Login
- 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