Java FileChannel Copy copyFolder(File fin, File fout)

Here you can find the source of copyFolder(File fin, File fout)

Description

copy Folder

License

Open Source License

Declaration

public static void copyFolder(File fin, File fout) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.nio.channels.FileChannel;

public class Main {
    public static void copyFolder(File fin, File fout) throws IOException {
        fout.mkdirs();//from ww  w  .j av a  2 s  .  com
        String[] children = fin.list();
        if (children == null) {
            // Either dir does not exist or is not a directory
        } else {
            for (int p = 0; p < children.length; p++) {
                File f = new File(fin + "/" + children[p]);
                File f1 = new File(fout + "/" + children[p]);
                if (f.isDirectory())
                    copyFolder(f, f1);
                else
                    copyFile(f, f1);
            }
        }
    }

    public static void copyFile(File source, File target)
            throws IOException {
        FileChannel sourceChannel = new FileInputStream(source)
                .getChannel();
        FileChannel targetChannel = new FileOutputStream(target)
                .getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
        sourceChannel.close();
        targetChannel.close();
    }
}

Related

  1. copyFileUsingChannel(File source, File dest)
  2. copyFileUsingChannel(File source, File dest)
  3. copyFileUsingFileChannels(File source, File dest)
  4. copyFileUsingFileChannels(File source, File dest)
  5. copyFileUsingFileChannels(File source, File dest)
  6. copyFromZip(ZipFile zipFile, String locationInBundle, File destination)
  7. copyInternal(FileInputStream in, FileOutputStream out)
  8. copyLarge(FileInputStream in, FileOutputStream out)
  9. copyNio(final File source_file, final File destination_file)