如何将一个文件夹内的所有文件复制到一个新的文件夹呀......

解决方案 »

  1.   

    java.io.File内应该有方法可以做到
      

  2.   

    一下程序能复制文件目录和目录下的文件:package filecopy;import java.io.*;public class Filecopy { /**
     * @param args
     */
    public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    if (args.length == 0)
    args = new String[] { "g:\\2", "g:\\1" };
    File frompath = new File(args[0]);
    File topath = new File(args[1]);
    String[] fromlist = frompath.list();
    for (int i = 0; i < fromlist.length; i++) {
    File fromfile = new File(frompath.getPath(), fromlist[i]);
    File tofile = new File(topath.getPath(), fromlist[i]);
    if (fromfile.isDirectory()) {
    tofile.mkdirs();
    System.out.println( fromfile.getCanonicalPath());
    main(new String[] { fromfile.getPath(), tofile.getPath() });
    }
    else {
    int ch;
    byte[] b = new byte[256];
    RandomAccessFile fin = new RandomAccessFile(fromfile, "r");
    RandomAccessFile fout = new RandomAccessFile(tofile, "rw");
    ch = fin.read(b);
    while (ch != -1) {
    fout.write(b);
    ch = fin.read(b);
    }
    fin.close();
    fout.close();
    }
    } }
    }