请教高手问题:在java中,我想调用windows的拷贝命令,怎么去调用啊。最好给段详细的代码。

解决方案 »

  1.   

    Runtime r  =  Runtime.getRuntime();
    String strCmd  =   "" ;
        String sFile  = "d:\\aa.txt";
        String dFile = "d:\\bk\\";
     try    {
                strCmd  =   " cmd /C start copy  "   +  sFile  +   "   "   +  dFile  +   " \n cmd /C exit " ;
                 r.exec(strCmd);}   catch (IOException e)   {
       e.printStackTrace();
    }
      

  2.   

    改进一下
    Runtime r  =  Runtime.getRuntime();
    String strCmd  =   "" ;
        String sFile  = "d:\\aa.txt";
        String dFile = "d:\\bk\\";
     try    {
                strCmd  =   " cmd /C start copy  "   +  sFile  +   "   "   +  dFile  +   "  ^&  exit " ;
                 r.exec(strCmd);}   catch (IOException e)   {
       e.printStackTrace();
    }