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

解决方案 »

  1.   

    Runtime.getRuntime().exec("cmd cls");就是清除控制台的内容,但我刚才试了下,没反应,可能是dos命令行不对。
    你看看下面这段程序是否对你有帮助:
    import java.io.*;
    public class RunOSCommand {public RunOSCommand() {
    }
    public static void main(String[] args) {
    System.out.println("in the main");
    try
    {
    Runtime r = Runtime.getRuntime();
    String cmd = "dir";
    Process p = r.exec(cmd);
    BufferedReader reader = new BufferedReader(new InputStreamReader(new
    DataInputStream( new BufferedInputStream(p.getInputStream()))));
    String lineRead =null;
    while( (lineRead = reader.readLine() ) != null)
    {
    System.out.println(lineRead);}
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }
      

  2.   

    楼上的,Runtime.getRuntime().exec("cmd cls");是新打开打开的cmd你当然看不到效果了,只有一种办法就是jni,写一个dll,取得当前的cmd的窗口句柄来处理
      

  3.   

    for(int i=0;i<n;i++)
    System.out.printlm("                        ");