如何在Java中清除控制台 – Eclipse SDK

我搜索得很远,但是找不到有用的东西……有办法! 所以,我需要的是一个清除Eclipse中控制台的代码(使其为空白)。 不,不打印50个空行,清除它!

我找到了这个:

Import import java.io.Console; public void ClearConsole() { Console console = System.console(); if (console == null) System.out.println("Couldn't get Console object !"); console.clear(); } 

但它给了我一个错误:“ 方法clear()未定义为类型控制台

在Eclipse工具中,您可以通过右键单击 + clear而不是Java来清除控制台面板。

控制台是一个日志工具,无法清除管理安全性。

我的回答可能会迟到,但这是我设法做的(这对我有用):

我根据本教程http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F创建了我的控制台,并将findConsole方法修改为如下所示:

 private MessageConsole findConsole(String name) { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); IConsole[] existing = conMan.getConsoles(); //if console exists, clear it for (int i = 0; i < existing.length; i++) if (name.equals(existing[i].getName())){ ((MessageConsole) existing[i]).clearConsole(); //this is the important part return myConsole; } myConsole = new MessageConsole(name, null); conMan.addConsoles(new IConsole[]{myConsole}); return myConsole; } 

所以,在其他一些按钮/控件/听众的监听器中,我有:

 myConsole = findConsole(ASIO_RECORD_OUTPUT); myConsoleOut = myConsole.newMessageStream(); 

每当执行该段代码时,我的控制台就会被清除。 希望能帮助到你。

编辑:忘了提,我在创建RCP应用程序时这样做了!