Java Directory Copy copyDirectory(File inputFolder, File outputFolder)

Here you can find the source of copyDirectory(File inputFolder, File outputFolder)

Description

copy Directory

License

Open Source License

Declaration

public static void copyDirectory(File inputFolder, File outputFolder) throws IOException 

Method Source Code


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

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static void copyDirectory(File inputFolder, File outputFolder) throws IOException {

        outputFolder.getParentFile().mkdirs();
        for (File innerFile : inputFolder.listFiles()) {
            if (innerFile.isDirectory()) {
                copyDirectory(innerFile, new File(outputFolder.getCanonicalPath() + "/" + innerFile.getName()));
            }//from   www  .java  2 s.  co m
            if (innerFile.isFile()) {
                copyFile(innerFile, new File(outputFolder.getCanonicalPath() + "/" + innerFile.getName()));
            }
        }

    }

    public static void copyFile(File inputFile, File outputFile) throws IOException {
        outputFile.getParentFile().mkdirs();
        FileReader in = new FileReader(inputFile);
        FileWriter out = new FileWriter(outputFile);
        int c;

        while ((c = in.read()) != -1)
            out.write(c);

        in.close();
        out.close();
    }
}

Related

  1. copyDirectory(File file, File folderDestino)
  2. copyDirectory(File from, File to)
  3. copyDirectory(File inDir, File outDir)
  4. copyDirectory(File inDir, File outDir)
  5. copyDirectory(File source, File destination)
  6. copyDirectory(File source, File destination)
  7. copyDirectory(File source, File destination)
  8. copyDirectory(File source, File destination)