当前位置: 技术问答>java相关
Java调用系统命令
来源: 互联网 发布时间:2015-04-09
本文导语: Windows98, JDK1.3.1 想调用系统的DIR命令,下面的程序老是出错 java.io.IOException: CreateProcess: dir error=0 哪位兄弟给指点一下。先谢过了。 import java.io.*; import java.lang.*; public class dir { public static void main(...
Windows98, JDK1.3.1
想调用系统的DIR命令,下面的程序老是出错
java.io.IOException: CreateProcess: dir error=0
哪位兄弟给指点一下。先谢过了。
import java.io.*;
import java.lang.*;
public class dir
{
public static void main(String args[])
{
try{
Process pr = Runtime.getRuntime().exec("dir"); // Calls "dir" command
StringBuffer sbOut = new StringBuffer(1000);
BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
while (true) {
String s = br.readLine();
if (s==null) break;
System.out.println(s);
}
br.close();
pr.waitFor();
System.out.println (sbOut.toString());
System.out.println ("Exit status: " + pr.exitValue());
} catch (Exception e) {
System.out.println ("Unexpected error executing cmd:" + e);
}
}
}
想调用系统的DIR命令,下面的程序老是出错
java.io.IOException: CreateProcess: dir error=0
哪位兄弟给指点一下。先谢过了。
import java.io.*;
import java.lang.*;
public class dir
{
public static void main(String args[])
{
try{
Process pr = Runtime.getRuntime().exec("dir"); // Calls "dir" command
StringBuffer sbOut = new StringBuffer(1000);
BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
while (true) {
String s = br.readLine();
if (s==null) break;
System.out.println(s);
}
br.close();
pr.waitFor();
System.out.println (sbOut.toString());
System.out.println ("Exit status: " + pr.exitValue());
} catch (Exception e) {
System.out.println ("Unexpected error executing cmd:" + e);
}
}
}
|
try
Process pr = Runtime.getRuntime().exec("cmd.exe /c dir");
Process pr = Runtime.getRuntime().exec("cmd.exe /c dir");