试图清除NetBeans中的输出窗口:CTRL + L起作用,因此我试图使用awt.Robot重新创建该命令。我环顾四周并尝试了System.out.flush();
,但该方法无效。我不想打印新行。
这是我的测试代码:
package test;
// import Robot, KeyEvent & AwtException
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class Test {
public static void main(String[] args) throws AWTException, InterruptedException {
// print text to output
System.out.println("Hello World!");
// initialize new robot, "keyPresser"
Robot keyPresser = new Robot();
// hold & release CTRL + L to theoretically clear the output window
keyPresser.keyPress(KeyEvent.VK_CONTROL);
Thread.sleep(500);
keyPresser.keyPress(KeyEvent.VK_L);
Thread.sleep(500);
keyPresser.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(500);
keyPresser.keyRelease(KeyEvent.VK_L);
Thread.sleep(500);
}
}
我走对了吗?这是做这件事的错误方法吗?我还可以使用哪些其他选项清除输出窗口?