1 Reply Latest reply on Jul 5, 2006 9:49 AM by 843790

    System (Runtime) execute command for copying the file

    843790
      Can any one tell me what is wrong with this - it throws an IOException

      String sourcepath = "C:"+File.separator+"pbx"+File.separator+"mantra"+File.separator+"vvvvv.mp3";
      String destinationpath = "C:"+File.separator+"rrr"+File.separator+"mantra"+File.separator+"mantra.mp3";
      Runtime rt=Runtime.getRuntime();
      try{
      String command="C:"+File.separator+"windows"+File.separator+"command /c copy "+sourcepath+" "+destinationpath;
      System.out.println(command);
      rt.exec(command);
      }catch(IOException ex){System.out.println("exception "+ex); ex.printStackTrace();}

      output:-
      C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra\mantra.mp3
      exception java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\
      rrr\mantra\mantra.mp3 error=2
      java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra
      \mantra.mp3 error=2
      at java.lang.Win32Process.create(Native Method)
      at java.lang.Win32Process.<init>(Win32Process.java:66)
      at java.lang.Runtime.execInternal(Native Method)
      at java.lang.Runtime.exec(Runtime.java:566)
      at java.lang.Runtime.exec(Runtime.java:428)
      at java.lang.Runtime.exec(Runtime.java:364)
      at java.lang.Runtime.exec(Runtime.java:326)
      at Test.main(Test.java:82)
        • 1. Re: System (Runtime) execute command for copying the file
          843790
          this is clear one...

          String sourcepath = "C:"+File.separator+"pbx"+File.separator+"mantra"+File.separator+"vvvvv.mp3";
          String destinationpath = "C:"+File.separator+"rrr"+File.separator+"mantra"+File.separator+"mantra.mp3";
          Runtime rt=Runtime.getRuntime();
          try{
          String command="C:"+File.separator+"windows"+File.separator+"cmd /c copy "+sourcepath+" "+destinationpath;
          // String command="copy "+sourcepath+" "+destinationpath;
          System.out.println(command);
          rt.exec(command);
          }catch(IOException ex){System.out.println("exception "+ex);
                      ex.printStackTrace();}