package files02;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class files02 {


	public static void main(String[] args) 
	{     
        //File source = new File("Test");
        //File target = new File("Test/subfolder");
        //copyDirectory(source, target);
        
        
        File source = new File("d:\\pipo");
        File target = new File("d:\\copier");
        copyDirectory(source, target);
        System.out.println("résultat");
        
    }
	
    public static void copyDirectory(File sourceLocation, File targetLocation)
     {

        String[] children = sourceLocation.list();
        if (sourceLocation.isDirectory()) {
            if (!targetLocation.exists()) {
                targetLocation.mkdir();
            }
            for (int i = 0; i < children.length; i++) {
                copyDirectory(new File(sourceLocation, children[i]), new File(
                        targetLocation, children[i]));
            }
        } else {
        	
        	try {
        	
		            InputStream in = new FileInputStream(sourceLocation);
		            OutputStream out = new FileOutputStream(targetLocation);
		            byte[] buf = new byte[1];
		            int length;
		            while ((length = in.read(buf)) > 0) {
		                out.write(buf, 0, length);
		            }
		            in.close();
		            out.close();
        	}
        	
        	catch (Exception e)
		    	 {
		    		
		    	 }

        }
    }



}

