[英]Clear IntelliJ console from java
Is there a way to clear IntelliJ console from code?有没有办法从代码中清除 IntelliJ 控制台? I've tried all the solutions I've found, like:我已经尝试了所有找到的解决方案,例如:
Runtime.getRuntime().exec("clear")
System.out.print("\033[H\033[2J");
System.out.flush();
I "hacked" it by literally clicking the "Clear All" icon: 我通过点击“全部清除”图标“破解”它:
public static void click(int x, int y) throws AWTException{
Robot bot = new Robot();
bot.mouseMove(x, y);
bot.mousePress(InputEvent.BUTTON1_MASK);
bot.mouseRelease(InputEvent.BUTTON1_MASK);
}
calling this with these coordinates on my screen: 在我的屏幕上用这些坐标调用它:
click(75,890);
IntelliJ IDEA console is not a real terminal, so there is no command to clear it from your Java code. IntelliJ IDEA 控制台不是真正的终端,因此没有命令可以从您的 Java 代码中清除它。
Try run your application in other console and you can make a function like this:尝试在其他控制台中运行您的应用程序,您可以创建如下函数:
public static void ClearConsole(){
try{
String operatingSystem = System.getProperty("os.name") //Check the current operating system
if(operatingSystem.contains("Windows")){
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cls");
Process startProcess = pb.inheritIO.start();
startProcess.waitFor();
} else {
ProcessBuilder pb = new ProcessBuilder("clear");
Process startProcess = pb.inheritIO.start();
startProcess.waitFor();
}
}catch(Exception e){
System.out.println(e);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.