运行DOS应用程序
import java.io.*;
import java.util.*;
/**
*
* @author zhuang
* @version
*/
public class dosexec
{
public static String[] runCommand(String[] cmd)
throws IOException
{
ArrayList list = new ArrayList();
Process proc = Runtime.getRuntime().exec(cmd);
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
String str;
while ((str = br.readLine()) != null)
list.add(str);
try
{
proc.waitFor();
}
catch (InterruptedException e)
{
System.err.println("process was interrupted");
}
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
br.close();
return (String[])list.toArray(new String[0]);
}
public static void main(String args[])
{
try
{
String[] comm = {"dir", "*.*"};
String outlist[] = runCommand(comm);
for (int i = 0; i < outlist.length; i++)
System.out.println(outlist[i]);
}
catch (IOException e)
{
System.out.println(e);
}
}
}
java.io.IOException: CreateProcess: dir *.* error=2
我的操作系统是window2000
有没有其它方法。