你的程序我不知道是怎么回事,但要实现dir的系统命令,下面的小程序就行
import java.io.*;public class DirList {
  public static void main(String[] args) {
    try {
      File path = new File(".");
      String[] list;
      if(args.length == 0)
        list = path.list();
      else 
        list = path.list(new DirFilter(args[0]));
      for(int i = 0; i < list.length; i++)
        System.out.println(list[i]);
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}class DirFilter implements FilenameFilter {
  String afn;
  DirFilter(String afn) { this.afn = afn; }
  public boolean accept(File dir, String name) {
    // Strip path information:
    String f = new File(name).getName();
    return f.indexOf(afn) != -1;
  }
} ///:~

解决方案 »

  1.   

    你的程序有两个错误:
    1、要执行DOS下的dir命令,需要使用:runtimeInstance.exec("cmd /c dir")。2、不能直接println(""+runtimeInstance.exec("dir")),这样的话runtimeInstance.exec("dir")直接就转换为字符串了!。从命令行执行指定程序:import java.lang.*;
    public class TestExec{
    public static void main(String args[])
    {
    try{
    Process pro = Runtime.getRuntime().exec("cmd /c a.bat");
            }
    catch(Exception ex){
    System.out.println("error");
    }
      }
    }
      

  2.   

    不是到你是要列出目录中的文件列表那还是要执行DOS下的dir命令那
      

  3.   

    sorry,上面的有一句写错了,应该是:Process pro = Runtime.getRuntime().exec("cmd /c start dir");应该加一个start参数就行了!!