......
try {
            String cmd = "cmd /c dir \\windows";//这里可以变换各种指令
            Process child = Runtime.getRuntime().exec(cmd);
            InputStream child_in = child.getInputStream();            System.out.println (cmd);
            BufferedReader  in=new BufferedReader(new InputStreamReader(child_in));
            String szstr1="";            while ((szstr1=in.readLine())!=null){
                System.out.println(szstr1);
            }
            child_in.close();
            in.close() ;
            child.destroy() ;
        } catch (IOException e) {
            System.err.println(e);
        }
......

解决方案 »

  1.   

    Process process = Runtime.getRuntime().exec("dir");
     String output;
     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
     while ( (output=bufferedReader.readLine()) != null)
     System.out.println(output);
      

  2.   

    Process process = Runtime.getRuntime().exec("dir");
    应该抛出异常吧,是不是的把路径指明了阿:c:/winnt/system32/cmd.exe dir我觉得是这样的,可以编译过去~~
      

  3.   

    当然是 我写个 dir 是举个例子罢了
    不过也不用写那么复杂
    像 dogcai(dogcai) 那样写就行了 cmd /c dir \\windows ...