import java.io.*;
public class Test4 {
public static void main(String[] args) {
//clear the screen(for Windows System)
try
{
Process process = Runtime.getRuntime().exec("ipconfig");
InputStreamReader ir=new InputStreamReader(process.getInputStream());
LineNumberReader in = new LineNumberReader (ir);
String line;
while ((line = in.readLine ()) != null)
System.out.println(line);
}
catch (Exception e) {
System.err.println ("IOException " + e.getMessage());
}
System.out.println("Hello");
System.out.println("How are you!");
}
}重新来一个就行,那个没有输出吧。

解决方案 »

  1.   

    import java.io.*;
    public class Test4 {
    public static void main(String[] args) {
    //clear the screen(for Windows System)
    try
    {
    Process process = Runtime.getRuntime().exec("ipconfig");
    }
    catch (Exception e) {
    System.err.println ("IOException " + e.getMessage());
    }
    System.out.println("Hello");
    System.out.println("How are you!");
    }
    }
    这就和行,呵呵,
      

  2.   

    对应行修改为如下:
    Process process = Runtime.getRuntime().exec("cmd.exe cls");
                                                 ^^^^^^^^^^^^^
      

  3.   

    ipconfig.exe是外部命令,当然可以
    cls是内部命令,必须要用cmd.exe cls或者start cls吧
      

  4.   

    好像还是不行耶!用cmd.exe调用的仅仅是cmd.exe而已,没用清屏!
    start cls也不行
      

  5.   

    嗯,对于cls,需要通过cmd来执行
      

  6.   

    不好意思,实在是不知道你说的实现清屏是什么意思?
    但是Runtime.getRuntime.exec()方法调用的程序都是没有图形化用户界面的,只是作为Java虚拟机建立的一个后台线程在运行,即使使用CLS清屏,你也是看不到任何结果的.
      

  7.   

    哦,还有,忘了说了,你的程序实际上相当于在运行中输入CLS,由于CLS不是可运行的程序或批处理文件,所以你的调用是一定会产生IOException的.
      

  8.   

    说实话,不太懂你的意思,假如你开了三个dos窗口
    你要清哪个屏?
      

  9.   

    再试试这个Process process = Runtime.getRuntime().exec("cmd.exe /c cls");