package files;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;

//http://stackoverflow.com/questions/24044995/copy-directory-files-into-subfolder

//http://www.mkyong.com/java/how-to-copy-directory-in-java/

//http://www.java2s.com/Tutorial/Java/0180__File/Catalog0180__File.htm

public class main
{

        public static void main(String[] args)
        {
           
        	File source = new File("d:\\pipo");
            File target = new File("d:\\copier\\tutu");
            copyDirectory(source, target);
            System.out.println("résultat");
           
        }
        
        
        
        public static void copyDirectory(File sourceLocation , File targetLocation)  
   	 	{
   			      
   			     if (sourceLocation.isDirectory()) 
   			     {
   			         if (!targetLocation.exists()) 
   			         {
   			             targetLocation.mkdir();
   			         }
   			          
   			         String[] children = sourceLocation.list();
   			         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);
   			          
   			         // Copy the bits from instream to outstream
   			         byte[] buf = new byte[1024];
   			         int len;
   			         while ((len = in.read(buf)) > 0) 
   			         {
   			             out.write(buf, 0, len);
   			         }
   			         
   			         in.close();
   			         out.close();
   			         
   			    	 }
   			    	catch (Exception e)
   			    	 {
   			    		
   			    	 }
   			         
   			     }
   	 }
        
}





