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!");
}
}重新来一个就行,那个没有输出吧。
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!");
}
}重新来一个就行,那个没有输出吧。
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!");
}
}
这就和行,呵呵,
Process process = Runtime.getRuntime().exec("cmd.exe cls");
^^^^^^^^^^^^^
cls是内部命令,必须要用cmd.exe cls或者start cls吧
start cls也不行
但是Runtime.getRuntime.exec()方法调用的程序都是没有图形化用户界面的,只是作为Java虚拟机建立的一个后台线程在运行,即使使用CLS清屏,你也是看不到任何结果的.
你要清哪个屏?