有两种方法1.调用系统命令。
2.完全靠java实现:java中没有现成的方法,只能自己遍历整个目录结构,然后一个个的拷贝。

解决方案 »

  1.   

    Runtime rt = Runtime.getRuntime();
    String com[] = new String[3];
    com[0] = "copy";
    com[1] = "c:\\temp";
    com[3] = "2:\\temp";
    rt.exec(com);
      

  2.   

    我要的是复制文件夹呀,用copy不行,用xcopy,发现在有的机器上用不了
      

  3.   

    而且,Runtime rt = Runtime.getRuntime();获取的是什么??我根据Dickensi的程序更改如下:
    Runtime rt = Runtime.getRuntime();
    String com[] = new String[3];
    com[0] = "copy";
    com[1] = "c:\\winzip.log";
    com[2] = "d:\\winzip.log";
    rt.exec(com);系统提示错误:
    java.io.IOException:CreateProcess:copy c:\winzip.log d:\winzip.log error=2
    请大家帮帮忙
      

  4.   

    而且,Runtime rt = Runtime.getRuntime();获取的是什么??我根据Dickensi的程序更改如下:
    Runtime rt = Runtime.getRuntime();
    String com[] = new String[3];
    com[0] = "copy";
    com[1] = "c:\\winzip.log";
    com[2] = "d:\\winzip.log";
    rt.exec(com);系统提示错误:
    java.io.IOException:CreateProcess:copy c:\winzip.log d:\winzip.log error=2
    请大家帮帮忙
      

  5.   

    import java.io.*;public class RunIt
    {
        public static void main(String[] args) throws Exception
        {
            run(args);
        }    public static void run(String[] cmds) throws Exception
        {
            String s = "cmd /c";
            for(int i=0;i<cmds.length;i++)
            {
                s+=" ";
                s+=cmds[i];
            }
            Process proc=Runtime.getRuntime().exec(s);//        System.out.println("result:");
            BufferedReader stdout = new BufferedReader(
                new InputStreamReader(proc.getInputStream()));
            String str;
            while((str=stdout.readLine())!=null)
            {
              System.out.println(str);
            }
            stdout.close();
            
    //        System.out.println("\nerror:");
            BufferedReader stderr = new BufferedReader(
                new InputStreamReader(proc.getErrorStream()));
            while((str=stderr.readLine())!=null)
            {
              System.out.println(str);
            }
            stderr.close();
        }
    }注意其中的cmd /c
      

  6.   

    import java.io.*;public class RunIt
    {
        public static void main(String[] args) throws Exception
        {
            run(args);
        }    public static void run(String[] cmds) throws Exception
        {
            String s = "cmd /c";
            for(int i=0;i<cmds.length;i++)
            {
                s+=" ";
                s+=cmds[i];
            }
            Process proc=Runtime.getRuntime().exec(s);//        System.out.println("result:");
            BufferedReader stdout = new BufferedReader(
                new InputStreamReader(proc.getInputStream()));
            String str;
            while((str=stdout.readLine())!=null)
            {
              System.out.println(str);
            }
            stdout.close();
            
    //        System.out.println("\nerror:");
            BufferedReader stderr = new BufferedReader(
                new InputStreamReader(proc.getErrorStream()));
            while((str=stderr.readLine())!=null)
            {
              System.out.println(str);
            }
            stderr.close();
        }
    }注意其中的cmd /c