就是说,我要在JAVA的程序中执行一次DOS命令,比如查看文件路径"DIR"或拷贝命令"copy"应该怎么在代码中调用这句DOS命令呢?

解决方案 »

  1.   

    import java.io.*;public class RunText
    {
        public static void main(String[]args)
        {
         if(args.length == 0)
         {
             System.out.println("请输入正确的文本文件路径!");
             return;
         }
         String path = args[0];
         try
         {
             Runtime.getRuntime().exec("cmd /c start dir");
         }
         catch(IOException e)
         {
             e.printStackTrace();
         }
        }
    }
      

  2.   

    import java.io.*;public class RunText
    {
        public static void main(String[]args)
        {
         try
         {
             Runtime.getRuntime().exec("cmd /c start dir");
         }
         catch(IOException e)
         {
             e.printStackTrace();
         }
        }
    }