import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;



public class CopyDir {
	
	public static void Process(String Nguon, String Dich) throws IOException{
		
		File TepTinDich = new File(Dich);
		if (!TepTinDich.exists()){
			new File(Dich.substring(0, (Dich.length() - TepTinDich.getName().length()))).mkdirs();
		}

		byte[] Mang = new byte[1024];
		int a;
		File TepTinNguon = new File(Nguon);
		
		if (TepTinNguon.isFile()){
			
			BufferedInputStream  bis = new BufferedInputStream(new FileInputStream(Nguon));
			BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(Dich));
			while ((a = bis.read(Mang)) != -1){
				bos.write(Mang);
			}
			bis.close();
			bos.close();
		}
		else{
			TepTinDich.mkdirs();
			File[] NoiDung = TepTinNguon.listFiles();
			for (int i = 0; i < NoiDung.length; i++) {
				Process(NoiDung[i].getAbsolutePath(), Dich + "\\" + NoiDung[i].getName());
			}
		}
	}
	
	public static void toCopy(String Nguon, String Dich){
	
	}
	public static void main(String[] args) throws IOException {
		String Nguon = "D:\\Dir";
		String Dich  = "D:\\Dir23";
		Process(Nguon, Dich);
	}
	}

