只能做到这步了。
Runtime.getRuntime().exec("c:\\winnt\\system32\\cmd.exe /c dir ");
后一步不知该如何做了

解决方案 »

  1.   

    import java.io.*;
    class PT
    {
      public static void main(String[] args) throws IOException
      {
      String filename="out.txt";
      if(args.length>0){
      filename=args[0];
      }
      String command="cmd /C dir";
      Runtime r=Runtime.getRuntime();
      Process p=r.exec(command);
      BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
      PrintStream ps=new PrintStream(new FileOutputStream(filename));
      String inline;
      while(null!=(inline=br.readLine())){
      ps.println(inline);
      }
      System.out.println("a command result has been readed to a file "+filename);
      }
    }
    另外,看看这个:
    http://expert.csdn.net/Expert/topic/1122/1122963.xml?temp=.7517206
      

  2.   

    cmd /C dir > c:\\temp.txt
      

  3.   

    cmd 后面的/c 表示什么意思?
      

  4.   

    不用写到文件中再读出来这么麻烦吧,Process有重定向流啊,直接读不就行了。
      

  5.   

    namowen(寒号不已) 果然厉害
      

  6.   

    http://expert.csdn.net/Expert/topic/1133/1133264.xml?temp=.6162989