Here you can find the source of copyDirectory(String srcDir, String destDir)
public static void copyDirectory(String srcDir, String destDir)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void copyDirectory(String srcDir, String destDir) { try {/* ww w . jav a 2s. c o m*/ File dDir = new File(destDir); File sDir = new File(srcDir); // if(!new File(srcDir).exists() && new File(destDir).exists()) // return ; dDir.mkdirs(); File[] file = sDir.listFiles(); int flength = file.length; for (int i = 0; i < flength; i++) { if (file[i].isFile() && !file[i].getName().endsWith(".dll")) { File sourceFile = file[i]; File targetFile = new File(dDir.getAbsolutePath() + File.separator + file[i].getName()); CopyFile(sourceFile, targetFile); } if (file[i].isDirectory() && file[i].getName().equals("granulej")) { String dir1 = srcDir + "/" + file[i].getName(); String dir2 = destDir + "/" + file[i].getName(); copyDirectory(dir1, dir2); } if (file[i].isDirectory() && file[i].getName().equals("lang")) { String dir1 = srcDir + "/" + file[i].getName(); String dir2 = destDir + "/" + file[i].getName(); copyDirectory(dir1, dir2); } } } catch (Exception e) { e.printStackTrace(); } } public static void CopyFile(File srcFile, File destFile) { try { int bytesum = 0; int byteread = 0; InputStream inStream = new FileInputStream(srcFile); FileOutputStream fs = new FileOutputStream(destFile); byte[] buffer = new byte[1444]; while ((byteread = inStream.read(buffer)) != -1) { bytesum += byteread; fs.write(buffer, 0, byteread); } inStream.close(); fs.close(); } catch (Exception e) { e.printStackTrace(); } } public static void CopyFile(String srcFile, String destFile) { try { File src = new File(srcFile); File dest = new File(destFile); if (!dest.exists()) { dest.createNewFile(); CopyFile(src, dest); } } catch (IOException e) { e.printStackTrace(); } } }